logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·02.11.26
← Back to news

NoiseLang: Where N = 5 is a Dirac delta

Original article
manualmeida.dev|85 points|39 comments|by manucorporat|Jul 6, 2026

NoiseLang: Where N=5N = 5N=5 is a Dirac delta

By Manu Martínez-Almeida July 6, 2026

During my undergraduate studies in telecommunications, I spent countless nights wrestling with signals and noise. I remember the tedious process of calculating expectations, variances, and the probability of random variables falling within specific bounds by hand.

Whenever I attempted to translate these mathematical concepts into code, I was met with an overwhelming amount of boilerplate.

"Everything is a distribution."

I first conceptualized a solution nearly a decade ago, but the project remained unfinished. Recently, however, I resurrected it. By leveraging modern AI tools, I was able to realize a vision far more sophisticated than what I could have achieved alone during my first attempt.


The Core Philosophy: Distributions as First-Class Citizens

The fundamental premise of NoiseLang is that every single value is a probability distribution.

In this paradigm, a standard constant is simply a Dirac delta—a distribution where 100% of the probability mass is concentrated on one specific value. Mathematically, if A=5A = 5A=5, it is represented as: δ(x−5)\delta(x - 5)δ(x−5)

Because constants and random variables are treated as the same type of object, every operator in the language is designed to map distributions to other distributions.

Handling Variables and Independence

A name in NoiseLang refers to a fixed node in a graph, mirroring how XXX remains the same variable throughout a mathematical proof. To achieve independence, you must explicitly perform separate "draws" using the ~ operator.

Example: Simulating two dice

X ~ unif_int(1, 6) 
Y ~ unif_int(1, 6) 
X + Y # This results in a true 2d6 distribution

The system is lazy; nothing is computed until a result is requested. For instance, calling P(X + Y > 10) triggers the runtime to execute millions of simulations across all available CPU cores to provide an estimate and its associated standard error.

Example: The Birthday Paradox

Bday = unif_int(1, 365) 
days ~[23] Bday # Draw 23 independent samples into a vector
P(has_duplicates(days)) # Returns ~0.507

From Spike to Bell Curve

The transformation of data in NoiseLang follows a visual and mathematical progression:

  1. The Constant: A = 5 is a single, infinitely thin spike.
  2. The Spread: D1 ~ unif_int(1, 6) transforms that spike into six equal bars (a discrete uniform distribution).
  3. The Convolution: Adding variables (S = A + D1 + D2) blends these shapes. The flat bars convolve into a triangle, which eventually curves into a Gaussian (bell) curve as more variables are added.
  4. The Collapse: A query like E(S) (the expected value) uses a Monte Carlo pass to average millions of samples, collapsing the distribution back into a single number (e.g., 121212).

Figure 1: Visualization of a constant becoming a distribution, then a bell curve, then a mean value.


The Engineering Journey

The high-level design was the easy part; a basic tree-walking interpreter could be built in a weekend. The real challenge lay in the infrastructure: naive interpretation →\rightarrow→ efficient Monte Carlo runtimes and conditional Bayesian inference.

The Role of AI Agents

I've been testing the limits of AI agents in my professional and personal work (such as porting an old Objective-C iOS game to a modern engine). With NoiseLang, I discovered a clear divide in AI capabilities:

  • Strengths: Writing JIT compilers, implementing numerical runtimes, and handling low-level boilerplate.
  • Weaknesses: High-level language design, maintaining orthogonality of features, and conceptualizing intuitive syntax.

Architecture: One IR, Three Paths

The ~ operator and distribution constructors build an append-only Directed Acyclic Graph (DAG) known as the RvGraph. This graph serves as the single source of truth for three different execution backends:

BackendPurposeCharacteristic
Batch InterpreterCorrectnessColumnar, works everywhere, acts as the "oracle."
Cranelift JITPerformanceFuses expressions into a single native machine kernel.
WASM EmitterPortabilityOptimized execution for web browsers.

If a backend cannot compile a specific expression, it falls back to the interpreter. All tests are run across all three paths to ensure they are bit-identical.


Optimizing the Monte Carlo Loop

The goal is simple: draw millions of samples, evaluate the expression, and reduce the result. To make this performant and deterministic, several techniques were employed:

  • Kernel Fusion: Intermediate values are kept in registers to avoid memory bottlenecks.
  • Fast Math: The xoshiro256++ PRNG is compiled directly into the kernel. Functions like ln, sin, and cos are replaced with inline polynomial approximations, yielding a 2×2\times2× speedup.
  • Parallel Streams: To overcome the serial nature of random number generation, the kernel runs four independent streams simultaneously, allowing out-of-order CPU cores to overlap execution.

Performance Benchmark: On an M4 Pro (14-core), a simple P(...) query can sustain approximately 5.8 billion samples per second.