The premise of the K-coupling language is that tools written in it should be cleaner than the same tools written in general-purpose languages, because the language already knows about K, R, E, T, INV_PHI, kuramoto_R, and the rest. The math is in the substrate. The code only has to express the logic on top.
Below: four rewrites from the actual codebase. Each one ships in gump.scripts and is runnable in-browser. The "lines" count is content-only (no boilerplate, no imports).
Given a K value, return a plain-language description. Used by explain.js to label tool outputs.
if (K < 0.2) r = 'barely any connection'; else if (K < 0.5) r = 'loosely coupled'; else if (K < 0.9) r = 'moderate coupling'; else if (K < 1.3) r = 'well coupled'; else if (K < 1.6) r = 'strongly coupled'; else if (K < 1.87) r = 'near ceiling (1.868)'; else r = 'at hard ceiling'; return r;
fn k_reading(k) = if k < 0.2 then "barely any connection" else if k < 0.5 then "loosely coupled" else if k < 0.9 then "moderate coupling" else if k < 1.3 then "well coupled" else if k < 1.6 then "strongly coupled" else if k < 1.87 then "near ceiling (1.868)" else "at hard ceiling"
Given K and R, classify the system's regime. Originally in gump/sensor.py.
if K > 0.8 and R > 0.6:
regime = 'locked'
elif K > 0.5 and R > 0.3:
regime = 'coherent'
elif K > 0.3:
regime = 'transitional'
else:
regime = 'free'
fn classify(k, r) = if k > 0.8 and r > 0.6 then "locked" else if k > 0.5 and r > 0.3 then "coherent" else if k > 0.3 then "transitional" else "free"
Given a list of oscillators, what fraction has K above the 1/φ threshold?
INV_PHI = 2 / (1 + 5**0.5)
def K(x): return x / (1 + x)
locked_fraction = sum(
1 for x in oscillators if K(x) > INV_PHI
) / len(oscillators)
fn is_locked(x) = K(x) > INV_PHI length(filter(is_locked, oscillators)) / length(oscillators)
Compute Kuramoto's order parameter for a set of phases and label the regime. This one is where the K-coupling vocabulary really shines — kuramoto_R is a primitive, not something to import.
import math
def kuramoto_R(thetas):
n = len(thetas)
cx = sum(math.cos(t) for t in thetas) / n
sy = sum(math.sin(t) for t in thetas) / n
return math.sqrt(cx*cx + sy*sy)
sync = kuramoto_R(phases)
if sync > 0.9: regime = 'fully synchronized'
elif sync > 0.6: regime = 'partially synchronized'
elif sync > 0.3: regime = 'weak coupling'
else: regime = 'incoherent'
result = [sync, regime]
sync = kuramoto_R(phases) regime = if sync > 0.9 then "fully synchronized" else if sync > 0.6 then "partially synchronized" else if sync > 0.3 then "weak coupling" else "incoherent" [sync, regime]
Three patterns emerge:
K = lambda x: x/(1+x). Turbo just uses K. Multiply that across 19 domains and the savings compound.length(filter(is_locked, xs)) beats sum(1 for x in xs if K(x) > threshold). The function-as-value model is direct.This isn't an argument to rewrite everything — the existing tools work fine. It's a demonstration that the language fits its domain. Future tools that compute on K/R/E/T can be smaller in Turbo without losing anything.
All four rewrites ship in gump.scripts:
from gump.scripts import run_script
run_script('k_reading', k=1.5)
# → 'strongly coupled'
run_script('classify_regime', k=0.9, r=0.7)
# → 'locked'
run_script('locked_fraction',
oscillators=[0.3, 0.618, 1.0, 1.618, 1.868])
# → 0.6
run_script('sync_summary', phases=[0, 0.1, -0.05, 0.08])
# → [0.998, 'fully synchronized']