code wiki / _hdl_build / nx_flip_defl.nx

nx_flip_defl.nx source

↩ module page · 154 lines · 6715 B

1// nx_flip_defl.nx -- MONETARY DEFLATION: separate a REAL gain from a debasement illusion. 2// Operator 2026-07-23: "only trade on real value not inflations". This is the LITERAL half. 3// A 40% nominal gain against 40% money-supply growth is a ZERO real gain -- the measuring unit shrank. 4// real_now = nominal_now * money_then / money_now ; debasement = nominal_gain - real_gain 5// VERDICTS: REAL-GAIN (survives) / ILLUSORY (nominal up, real flat/down = the trap) / REAL-LOSS. 6// FAIL-CLOSED: an absent series/period is REFUSED, never silently treated as zero inflation. 7// The deflator series lives in flip-mon- as DATA (M2SA today; CPI/PPI/gold/any unit tomorrow). 8// 9// CONVERTED ONTO THE SHARED BASE nx_flip_lib.nx (fx_*); only the two deflator-specific helpers 10// (fd_lookup by series+period, fd_period_cmp ordering guard) remain local. Equivalence PROVEN by 11// nx_flip_gate staying 16/16 across the swap. 12// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 13import "nx_flip_lib.nx" 14import "nx_syscalls.nx" 15 16const FD_ARGC_MIN: i64 = 6 17const FD_ARG_PFX: i64 = 6 18const FD_M_SERIES: i64 = 1 19const FD_M_PERIOD: i64 = 2 20const FD_M_VALUE: i64 = 3 21 22// find the observation for (series, period). returns value, or -1 if ABSENT (fail-closed sentinel). 23func fd_lookup(b: *u8, n: i64, series: *u8, period: *u8, sp: *i64) -> i64 { 24 var i: i64 = 0 25 var got: i64 = 0 - 1 26 while i < n { 27 let le: i64 = fx_line_end(b, n, i) 28 if le > i { if got < 0 { 29 var hit: i64 = 0 30 if fx_col(b, i, le, FD_M_SERIES, sp) == 1 { 31 if fx_slice_eqs(b, sp[0], sp[1], series) == 1 { hit = 1 } 32 } 33 if hit == 1 { 34 if fx_col(b, i, le, FD_M_PERIOD, sp) == 1 { 35 if fx_slice_eqs(b, sp[0], sp[1], period) == 1 { 36 if fx_col(b, i, le, FD_M_VALUE, sp) == 1 { got = fx_slice_atoi(b, sp[0], sp[1]) } 37 } 38 } 39 } 40 } } 41 i = le + 1 42 } 43 return got 44} 45 46// lexical compare of two YYYY-MM period strings: <0 a before b, 0 equal, >0 a after b 47func fd_period_cmp(a: *u8, b: *u8) -> i64 { 48 var i: i64 = 0 49 while a[i] != (0 as u8) { 50 if b[i] == (0 as u8) { return 1 } 51 let ca: i64 = a[i] as i64 52 let cb: i64 = b[i] as i64 53 if ca < cb { return 0 - 1 } 54 if ca > cb { return 1 } 55 i = i + 1 56 } 57 if b[i] != (0 as u8) { return 0 - 1 } 58 return 0 59} 60 61func main(argc: i64, argv: *i64) -> i64 { 62 if argc < FD_ARGC_MIN { 63 fx_puts("usage: nx_flip_defl <series> <period-then> <period-now> <nominal-then> <nominal-now> [plane-prefix-root]\n" as *u8) 64 fx_puts(" deflator observations are read from <root>mon- ; an absent period is REFUSED, never assumed zero\n" as *u8) 65 sys_exit(FX_EXIT_USAGE) 66 return FX_EXIT_USAGE 67 } 68 let series: *u8 = argv[1] as *u8 69 let p_then: *u8 = argv[2] as *u8 70 let p_now: *u8 = argv[3] as *u8 71 let nom_then: i64 = fx_atoi(argv[4] as *u8) 72 let nom_now: i64 = fx_atoi(argv[5] as *u8) 73 74 var root: *u8 = "flip-" as *u8 75 if argc > FD_ARG_PFX { root = argv[FD_ARG_PFX] as *u8 } 76 let nmp: *i64 = sts_mm(FX_SCRATCH) as *i64 77 let bm: *u8 = fx_plane(root, "mon-" as *u8, nmp) 78 let nm: i64 = nmp[0] 79 let sp: *i64 = sts_mm(FX_SCRATCH) as *i64 80 81 if nm == 0 { 82 fx_puts("FLIP-RED reason=monetary-plane-empty prefix=" as *u8); fx_puts(fx_cat2(root, "mon-" as *u8)); fx_puts("\n" as *u8) 83 fx_puts("verdict=REFUSED\n" as *u8) 84 sys_exit(FX_EXIT_REFUSED) 85 return FX_EXIT_REFUSED 86 } 87 if nom_then <= 0 { 88 fx_puts("FLIP-RED reason=nominal-then-must-be-positive\n" as *u8) 89 fx_puts("verdict=REFUSED\n" as *u8) 90 sys_exit(FX_EXIT_REFUSED) 91 return FX_EXIT_REFUSED 92 } 93 let m_then: i64 = fd_lookup(bm, nm, series, p_then, sp) 94 let m_now: i64 = fd_lookup(bm, nm, series, p_now, sp) 95 if m_then <= 0 { 96 fx_puts("FLIP-RED reason=deflator-observation-absent series=" as *u8); fx_puts(series) 97 fx_puts(" period=" as *u8); fx_puts(p_then); fx_puts("\n" as *u8) 98 fx_puts("verdict=REFUSED\n" as *u8) 99 fx_puts("rule=absent-deflator-would-fake-a-real-gain-out-of-pure-debasement\n" as *u8) 100 sys_exit(FX_EXIT_REFUSED) 101 return FX_EXIT_REFUSED 102 } 103 if m_now <= 0 { 104 fx_puts("FLIP-RED reason=deflator-observation-absent series=" as *u8); fx_puts(series) 105 fx_puts(" period=" as *u8); fx_puts(p_now); fx_puts("\n" as *u8) 106 fx_puts("verdict=REFUSED\n" as *u8) 107 fx_puts("rule=absent-deflator-would-fake-a-real-gain-out-of-pure-debasement\n" as *u8) 108 sys_exit(FX_EXIT_REFUSED) 109 return FX_EXIT_REFUSED 110 } 111 if fd_period_cmp(p_then, p_now) >= 0 { 112 fx_puts("FLIP-RED reason=period-order-invalid then=" as *u8); fx_puts(p_then) 113 fx_puts(" now=" as *u8); fx_puts(p_now); fx_puts("\n" as *u8) 114 fx_puts("verdict=REFUSED\n" as *u8) 115 fx_puts("rule=then-must-precede-now-a-swapped-pair-inverts-the-deflator-silently\n" as *u8) 116 sys_exit(FX_EXIT_REFUSED) 117 return FX_EXIT_REFUSED 118 } 119 120 let real_now: i64 = nom_now * m_then / m_now 121 let nom_gain: i64 = (nom_now - nom_then) * FX_BPS / nom_then 122 let real_gain: i64 = (real_now - nom_then) * FX_BPS / nom_then 123 let money_growth: i64 = (m_now - m_then) * FX_BPS / m_then 124 let debasement: i64 = nom_gain - real_gain 125 126 var vcode: i64 = 0 127 if real_gain > 0 { vcode = 1 } else { if nom_gain > 0 { vcode = 2 } } 128 129 fx_puts("FLIP-DEFL\n" as *u8) 130 fx_puts("series=" as *u8); fx_puts(series) 131 fx_puts(" then=" as *u8); fx_puts(p_then) 132 fx_puts(" now=" as *u8); fx_puts(p_now); fx_puts("\n" as *u8) 133 fx_puts("verdict=" as *u8) 134 if vcode == 1 { fx_puts("REAL-GAIN" as *u8) } 135 if vcode == 2 { fx_puts("ILLUSORY" as *u8) } 136 if vcode == 0 { fx_puts("REAL-LOSS" as *u8) } 137 fx_puts(" nominal_gain_bps=" as *u8); fx_putn(nom_gain) 138 fx_puts(" real_gain_bps=" as *u8); fx_putn(real_gain) 139 fx_puts(" money_growth_bps=" as *u8); fx_putn(money_growth) 140 fx_puts(" debasement_bps=" as *u8); fx_putn(debasement) 141 fx_puts("\n" as *u8) 142 fx_puts("rule=" as *u8) 143 if vcode == 1 { fx_puts("gain-survives-deflation-this-is-real-value\n" as *u8) } 144 if vcode == 2 { fx_puts("nominal-up-real-flat-or-down-the-unit-shrank-not-your-wealth\n" as *u8) } 145 if vcode == 0 { fx_puts("real-loss-before-and-after-deflation\n" as *u8) } 146 147 fx_kv("nominal_then" as *u8, nom_then) 148 fx_kv("nominal_now" as *u8, nom_now) 149 fx_kv("real_now_in_then_money" as *u8, real_now) 150 fx_kv("deflator_then" as *u8, m_then) 151 fx_kv("deflator_now" as *u8, m_now) 152 sys_exit(0) 153 return 0 154}