← Turbo

Tools, rewritten

side-by-side: the original code vs the K-coupling language

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).

Note: the original code is not "bad" — it's perfectly fine. The point is what happens when the substrate is shaped right. Same logic, half the syntax noise.

01 · K reading (plain-language label)

Given a K value, return a plain-language description. Used by explain.js to label tool outputs.

explain.js (JavaScript)8 lines
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;
Turbo8 lines
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"
k =

02 · Regime classifier

Given K and R, classify the system's regime. Originally in gump/sensor.py.

sensor.py (Python)7 lines
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'
Turbo4 lines
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"
k = r =

03 · Locked fraction

Given a list of oscillators, what fraction has K above the 1/φ threshold?

Python3 lines
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)
Turbo2 lines
fn is_locked(x) = K(x) > INV_PHI

length(filter(is_locked, oscillators))
  / length(oscillators)
oscillators =

04 · Sync summary

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.

Python12 lines
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]
Turbo6 lines
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]
phases =

What the rewrites show

Three patterns emerge:

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:

Use them from Python
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']
GUMP · Tools · Support
Loading runtime…