code wiki / _hdl_build / nx_lifecycle.nx
nx_lifecycle.nx source
↩ module page · 45 lines · 2307 B
1// nx_lifecycle.nx -- LIB: the WEAR / REPAIR / ETERNAL lifecycle twin. Adds the time dimension to the product twin:
2// per part a wear life (days), a part cost and a LABOR (effort) cost to replace, and whether it is replaceable. From
3// these the system is judged in three regimes (operator's framing):
4// ETERNAL -- every part replaceable -> the system lasts forever, swapped piece by piece (Ship of Theseus).
5// EVOLVING -- each replacement uses a BETTER part -> capability ratchets up over cycles.
6// LIMITED -- when the LABOR to replace exceeds the part cost, early refresh wastes effort, so replacement is
7// RECOMMENDED only after X days (at wear-out); a non-replaceable part caps the whole system's life.
8// never-brick #26: pure arithmetic, bounded, deterministic. license_tier: ORIGINAL
9import "nx_syscalls.nx"
10
11// the system is ETERNAL iff every part is replaceable.
12func lc_is_eternal(replaceable: *i64, n: i64) -> i64 {
13 var i: i64 = 0
14 while i < n { if replaceable[i] == 0 { return 0 } i = i + 1 }
15 return 1
16}
17
18// limiting lifespan = min wear-life among NON-replaceable parts; 0-1 if all replaceable (eternal, no cap).
19func lc_bottleneck_life(lifespan: *i64, replaceable: *i64, n: i64) -> i64 {
20 var best: i64 = 0 - 1
21 var i: i64 = 0
22 while i < n {
23 if replaceable[i] == 0 {
24 if best < 0 { best = lifespan[i] } else { if lifespan[i] < best { best = lifespan[i] } }
25 }
26 i = i + 1
27 }
28 return best
29}
30
31// recommended replacement day: if labor (effort) > part cost, refreshing early wastes effort -> replace at wear-out
32// (X = full life); else parts dominate (cheap labor) -> replace proactively at 80% of life.
33func lc_replace_day(lifespan: i64, part_cost: i64, labor_cost: i64) -> i64 {
34 if labor_cost > part_cost { return lifespan }
35 return (lifespan * 80) / 100
36}
37
38// EVOLVING: capability after `cycles` better-part replacements.
39func lc_evolving_cap(base: i64, gain: i64, cycles: i64) -> i64 { return base + gain * cycles }
40
41// lifetime maintenance cost over a horizon = (horizon / life) replacements * (part + labor) cost.
42func lc_maint_cost(part_cost: i64, labor_cost: i64, horizon: i64, lifespan: i64) -> i64 {
43 if lifespan <= 0 { return 0 }
44 return (horizon / lifespan) * (part_cost + labor_cost)
45}