code wiki / _hdl_build / nx_lossless_language.nx

nx_lossless_language.nx source

↩ module page · 52 lines · 2864 B

1// nx_lossless_language.nx -- building a LOSSLESS LANGUAGE to interface with generators (Z-Image, 2// LTX video, music AI): a conditioning language where terms map to intent so precisely that 3// "Diora Baird golfing as a video" generates EXACTLY that, net-new. Fidelity-to-spec is the 4// DISTORTION signal; building the language is RATE-DISTORTION OPTIMIZATION of the conditioning -- 5// the LOSSY-generation sibling of our Kolmogorov/Levin governor (lossless shortest-description). 6// 7// The closed loop the SYSTEM runs (not the human hunting LoRAs by hand): 8// spec -> generate -> MEASURE fidelity-to-spec (nx_image_fidelity / a semantic scorer) -> 9// REFINE the language (better term / caption / identity embedding / control / LoRA) -> repeat 10// until distortion falls below the Council floor = the language is LOSSLESS for that intent. 11// This module models that convergence: given the fidelity attained at each refinement step, it 12// finds WHEN the language became lossless and at what RATE (how much refinement it cost) -- the 13// rate-distortion curve of the language. Each refinement should not regress (a sound search). 14// license_tier: ORIGINAL Refs: Shannon rate-distortion; the precision-measurement loop. 15 16import "nx_syscalls.nx" 17 18const LL_LOSSLESS_FLOOR: i64 = 950 // fidelity-to-spec >= 95% (permil) = effectively lossless 19 20// distortion = the gap from a perfect (lossless) match, in permil. 21func ll_distortion(fidelity_permil: i64) -> i64 { return 1000 - fidelity_permil } 22 23func ll_is_lossless(fidelity_permil: i64, floor: i64) -> i64 { if fidelity_permil >= floor { return 1 } return 0 } 24 25// the RATE: the first refinement step whose fidelity reaches lossless (how much language it cost), 26// or -1 if the language never became lossless within the given refinements. 27func ll_converge_step(scores: *i64, n: i64, floor: i64) -> i64 { 28 var i: i64 = 0 29 while i < n { if scores[i] >= floor { return i } i = i + 1 } 30 return 0 - 1 31} 32 33// a SOUND language search never regresses fidelity as it refines (each added term/control helps or 34// holds). Returns 1 if monotone non-decreasing, else 0 (a regression = a bad refinement operator). 35func ll_is_monotone(scores: *i64, n: i64) -> i64 { 36 var i: i64 = 1 37 while i < n { if scores[i] < scores[i - 1] { return 0 } i = i + 1 } 38 return 1 39} 40 41// total distortion removed across the refinement (how much the language closed the intent gap). 42func ll_distortion_removed(scores: *i64, n: i64) -> i64 { 43 if n <= 0 { return 0 } 44 return scores[n - 1] - scores[0] 45} 46 47// marginal value of refinement step k (distortion removed by that one term/control) -- so the team 48// can keep the high-value refinements and drop the ones that barely move fidelity (a lean language). 49func ll_marginal(scores: *i64, k: i64) -> i64 { 50 if k <= 0 { return scores[0] } 51 return scores[k] - scores[k - 1] 52}