Chapter 2: Zero-AST Composition Algebra (^, &, |>, ∇)
Chapter 2: Zero-AST Composition Algebra (^, &, |>, ∇)
Lineage: Green/Red/Purple Dragon (ASTs, Attribute Grammars, IR Graphs) → White Dragon (Algebraic Sections & Intersections)
Live Proof:packages/@awesome-os/stealify-schema/src/algebra.mts&b8g-gen verify
2.1 Beyond Heavyweight Abstract Syntax Trees
In the classical Dragon Books, every transformation begins by parsing source text into a sprawling, pointer-heavy Abstract Syntax Tree (AST), running multi-pass visitors over it, and lowering it into an intermediate representation. That pipeline works for a single language frontend, but it collapses when composing heterogeneous system boundaries — memory arenas, capability tokens, GPU surfaces, audio/video sinks, and OS syscalls.
When system contracts are expressed as ad-hoc ASTs or C++ class hierarchies, composition errors (field collisions, privilege escalation, unpaced host I/O, half-mutated state) only surface at runtime — or require a custom compiler plugin per subsystem.
The White Dragon Principle: System architecture does not need a bespoke AST. Memory slices, capabilities, host boundaries, and Copy-on-Write (CoW) state transitions all obey a four-operator composition algebra directly in erasable TypeScript (erasableSyntaxOnly: true, zero node:* imports) and lower directly to flat C11/WASM structs.
2.2 The Four First-Principles Operators
| Operator | Symbol | Function | Algebraic Invariant | |
|---|---|---|---|---|
| Exterior Product | ^ |
wedge(id, A, B) |
Composes orthogonal Sections iff keyof A ∩ keyof B = ∅; collisions collapse to a compile-time type error and runtime WedgeCollapseError. |
|
| Meet-Semilattice | & |
meet(c1, c2) |
Computes the greatest lower bound of capability scopes (c1.scopes ∩ c2.scopes, max(epoch)). Authority can only shrink, never escalate. |
|
| Manifold Projection | `\ | >` | project(M, C) |
Projects an internal manifold onto a target chart (wgpu, vt100, http, uefi, sab). Legacy host charts structurally enforce pacing policies. |
| Monotonic Evolution | ∇ |
evolve(S, fn) |
Applies a Copy-on-Write epoch delta with deterministic O(1) snapshot rollback — eliminating partial-mutation corruption. |
2.3 Portable Sections and Orthogonal Intersections
A Section (defineSection) declares a minimal, self-contained slice of typed fields with zero hidden ambient state. Two Sections compose into an Intersection (intersect via wedge) if and only if their field subspaces are strictly disjoint:
import { defineSection, f, intersect } from './schema-definition.mts'
import { wedge, createCapability, meet } from './algebra.mts'
// 1. Define two portable, self-contained Sections
const FrameSection = defineSection('frame', {
width: f.u32(),
height: f.u32(),
strideBytes: f.u32(),
})
const AudioSection = defineSection('audio', {
sampleRate: f.u32(),
channels: f.u16(),
})
// 2. Exterior product (FrameSection ^ AudioSection):
// Compile-time proof that keyof FrameSection & keyof AudioSection === never.
// Internally lowers to intersect('av-frame', [FrameSection, AudioSection]).
export const AvFrameIntersection = wedge('av-frame', FrameSection, AudioSection)
// 3. Meet-semilattice (hostCap & tabCap): authority can only narrow
const hostCap = createCapability(['gpu:submit', 'audio:write', 'fs:read'] as const, 2)
const tabCap = createCapability(['gpu:submit', 'audio:write'] as const, 4)
const scoped = meet(hostCap, tabCap) // scopes: ['audio:write', 'gpu:submit'], epoch: 4
If an engineer accidentally adds a colliding channels field to FrameSection, TypeScript rejects the wedge() call at compile time via AssertOrthogonalFields<TFieldsA, TFieldsB> — and any dynamic loader rejects it immediately with WedgeCollapseError before a single byte is mapped.
2.4 Zero-AST Projection Lowering (|>)
Because Sections and Intersections carry flat field descriptors rather than opaque AST nodes, projecting a composed manifold across targets (wgpu, vt100, http, uefi, sab) requires zero parser passes:
- Internal Charts (
sab,wgpu) bind directly toB8G_ARENA_V1offsets with zero serialization. - Legacy Host Charts (
vt100,http,uefi) structurally require a pacing and backpressure descriptor at the type level, preventing fast Post-Neumann producers from overwhelming slow Von Neumann sinks.
2.5 Historical Contrast: AST Compilers vs. Composition Algebra
| Dimension | Classical Dragon Compilers (1977–2006) | White Dragon Composition Algebra (2026) |
|---|---|---|
| Intermediate Form | Pointer-chasing AST / CFG / SSA graphs | Flat SectionDefinition & IntersectionDefinition descriptors |
| Collision Detection | Linker symbol clash or silent struct shadowing | Compile-time AssertOrthogonalFields + runtime WedgeCollapseError |
| Security Model | Ambient process authority; ad-hoc ACL checks | Algebraic meet(&) semilattice — escalation is unrepresentable |
| State Mutation | Destructive in-place updates; complex undo logs | Monotonic evolve(∇) CoW epochs with O(1) rollback |
| Cross-Language Emit | Separate IDL compiler (protoc, mojom, WebIDL) |
Single source defineSection lowers to TS, C11, and WASM |
With orthogonal system boundaries defined algebraically, Chapter 3 shows how those boundaries materialize at native machine speed: Zero-Header C11 B8G-ABI Dispatch Tables.