code wiki / _hdl_build / nx_meal_effort_gate.nx
nx_meal_effort_gate.nx source
↩ module page · 162 lines · 9130 B
1// nx_meal_effort_gate.nx -- proves the opportunity-cost engine on per-run /tmp fixtures.
2//
3// The cell that matters is T6: the SAME dish, the SAME prices, the SAME alternatives -- and the recommendation
4// FLIPS from "buy it pre-prepped" to "cook it" purely because the cook got better with a knife. If that cell
5// ever goes vacuous, skill has stopped being a term in the arithmetic and the coach is decoration.
6// license_tier: ORIGINAL No hw writes (Rule 26).
7import "nx_syscalls.nx"
8import "nx_meal_effort.nx"
9import "nx_gate_verdict.nx"
10
11const EG_PFX: i64 = 200
12const EG_FLD: i64 = 1024
13const EG_RATE: i64 = 2500 // $25.00/hour, in cents
14const EG_SCRATCH_MONEY: i64 = 1977
15
16func main(argc: i64, argv: *i64) -> i64 {
17 let ctr: *i64 = gv_ctr()
18 gv_head("nx_meal_effort -- is cooking this the right use of the evening, given who is holding the knife" as *u8)
19
20 let ep: i64 = sys_now_realtime_sec()
21 let pfx: *u8 = sys_mmap(EG_PFX)
22 var o: i64 = as_append(pfx, 0, "/tmp/mef_" as *u8)
23 o = fd_apnum(pfx, o, ep)
24 o = as_append(pfx, o, "-" as *u8)
25 pfx[o] = 0 as u8
26
27 let rid: *u8 = "beefstew" as *u8
28
29 // ---- the skill tree: broad -> specific ----
30 ef_add_skill(pfx, "knife" as *u8, "Knife skills" as *u8, ef_empty(), "Everything done with a blade on a board" as *u8)
31 ef_add_skill(pfx, "dicing" as *u8, "Dicing" as *u8, "knife" as *u8, "Even cubes, consistent size" as *u8)
32 ef_add_skill(pfx, "dice-onion" as *u8, "Dice an onion" as *u8, "dicing" as *u8, "Root-on, horizontal then vertical, claw grip" as *u8)
33 ef_add_skill(pfx, "chop-veg" as *u8, "Rough-chop vegetables" as *u8, "knife" as *u8, "Carrot and celery to even pieces" as *u8)
34 ef_add_skill(pfx, "heat" as *u8, "Heat control" as *u8, ef_empty(), "Reading a pan and adjusting" as *u8)
35 ef_add_skill(pfx, "sear" as *u8, "Searing" as *u8, "heat" as *u8, "Dry surface, hot pan, do not crowd" as *u8)
36 ef_add_skill(pfx, "braise" as *u8, "Braising" as *u8, "heat" as *u8, "Bare tremble, lid on, low and long" as *u8)
37
38 // ---- the dish, as ACTIVE steps (the braise's 3 unattended hours are not the cook's time) ----
39 ef_add_step(pfx, rid, 0, "Dice the onion" as *u8, "dice-onion" as *u8, 300)
40 ef_add_step(pfx, rid, 1, "Chop the carrot and celery" as *u8, "chop-veg" as *u8, 300)
41 ef_add_step(pfx, rid, 2, "Brown the chuck in batches" as *u8, "sear" as *u8, 600)
42 ef_add_step(pfx, rid, 3, "Build and set the braise" as *u8, "braise" as *u8, 300)
43
44 // ---- the pace multipliers, as DATA (base seconds = a competent cook, level 2) ----
45 ef_set_tmul(pfx, 0, 2500)
46 ef_set_tmul(pfx, 1, 1800)
47 ef_set_tmul(pfx, 2, 1000)
48 ef_set_tmul(pfx, 3, 850)
49 ef_set_tmul(pfx, 4, 700)
50
51 // ---- three households ----
52 ef_set_level(pfx, "novice" as *u8, "dice-onion" as *u8, 0)
53 ef_set_level(pfx, "novice" as *u8, "chop-veg" as *u8, 0)
54 ef_set_level(pfx, "novice" as *u8, "sear" as *u8, 0)
55 ef_set_level(pfx, "novice" as *u8, "braise" as *u8, 0)
56 ef_set_timevalue(pfx, "novice" as *u8, EG_RATE)
57
58 ef_set_level(pfx, "expert" as *u8, "dice-onion" as *u8, 4)
59 ef_set_level(pfx, "expert" as *u8, "chop-veg" as *u8, 4)
60 ef_set_level(pfx, "expert" as *u8, "sear" as *u8, 4)
61 ef_set_level(pfx, "expert" as *u8, "braise" as *u8, 4)
62 ef_set_timevalue(pfx, "expert" as *u8, EG_RATE)
63
64 // never watched braising -- deliberately one unmeasured skill
65 ef_set_level(pfx, "partial" as *u8, "dice-onion" as *u8, 2)
66 ef_set_level(pfx, "partial" as *u8, "chop-veg" as *u8, 2)
67 ef_set_level(pfx, "partial" as *u8, "sear" as *u8, 2)
68 ef_set_timevalue(pfx, "partial" as *u8, EG_RATE)
69
70 // fully skilled, but has never said what an hour of theirs is worth
71 ef_set_level(pfx, "nowage" as *u8, "dice-onion" as *u8, 4)
72 ef_set_level(pfx, "nowage" as *u8, "chop-veg" as *u8, 4)
73 ef_set_level(pfx, "nowage" as *u8, "sear" as *u8, 4)
74 ef_set_level(pfx, "nowage" as *u8, "braise" as *u8, 4)
75
76 // ---- the alternatives ----
77 ef_add_alt(pfx, rid, "prepped" as *u8, 2600, 12, "store deli counter" as *u8, "2026-08-05" as *u8)
78 ef_add_alt(pfx, rid, "frozen" as *u8, 2900, 10, "freezer aisle" as *u8, "2026-08-04" as *u8)
79 ef_add_alt(pfx, rid, "restaurant" as *u8, 3600, 0, "neighbourhood bistro" as *u8, "2026-08-06" as *u8)
80
81 // ---- T1 the skill tree reads broad -> specific ----
82 let path: *u8 = sys_mmap(EG_FLD)
83 var t1: i64 = 1
84 if ef_skill_path(pfx, "dice-onion" as *u8, path) != 3 { t1 = 0 }
85 if fd_streq(path, "Knife skills > Dicing > Dice an onion" as *u8) == 0 { t1 = 0 }
86 ef_skill_path(pfx, "sear" as *u8, path)
87 if fd_streq(path, "Heat control > Searing" as *u8) == 0 { t1 = 0 }
88 gv_check("T1 skill tree resolves broad to specific: Knife skills > Dicing > Dice an onion" as *u8, t1, ctr)
89
90 // ---- T2 the same step takes different people different time ----
91 var t2: i64 = 1
92 if ef_step_time(pfx, "novice" as *u8, rid, 0) != 750 { t2 = 0 } // 300 x 2.5
93 if ef_step_time(pfx, "expert" as *u8, rid, 0) != 210 { t2 = 0 } // 300 x 0.7
94 let tmn: *i64 = sys_mmap(8 * 4) as *i64
95 ef_cook_time(pfx, "novice" as *u8, rid, tmn)
96 if tmn[0] != 3750 { t2 = 0 }
97 if tmn[1] != 0 { t2 = 0 }
98 let tme: *i64 = sys_mmap(8 * 4) as *i64
99 ef_cook_time(pfx, "expert" as *u8, rid, tme)
100 if tme[0] != 1050 { t2 = 0 }
101 gv_check("T2 active time is per-cook: 62.5 min for the novice, 17.5 min for the expert, same dish" as *u8, t2, ctr)
102
103 // ---- T3 BITE: an unmeasured skill is not a fast skill ----
104 let tmp2: *i64 = sys_mmap(8 * 4) as *i64
105 ef_cook_time(pfx, "partial" as *u8, rid, tmp2)
106 var unk_bad: i64 = 0
107 if tmp2[1] > 0 { unk_bad = 1 }
108 var unk_good: i64 = 0
109 if tme[1] > 0 { unk_good = 1 }
110 gv_bite("T3 unmeasured-skill detector fires on the cook we never watched braise, silent on the assessed one" as *u8, unk_bad, unk_good, ctr)
111
112 // ---- T4 BITE: no invented wage ----
113 var wage_bad: i64 = 0
114 if ef_time_is_valued(pfx, "nowage" as *u8) == 0 { wage_bad = 1 }
115 var wage_good: i64 = 0
116 if ef_time_is_valued(pfx, "expert" as *u8) == 0 { wage_good = 1 }
117 var t4b: i64 = 1
118 if ef_time_cost(3750, 0) != 0 { t4b = 0 }
119 if ef_time_cost(3750, EG_RATE) != 2604 { t4b = 0 }
120 gv_bite("T4a unvalued-time detector fires on the household that never priced an hour, silent on the one that did" as *u8, wage_bad, wage_good, ctr)
121 gv_check("T4b an unset rate yields ZERO time cost -- never a plausible-looking invented wage" as *u8, t4b, ctr)
122
123 // ---- T5 only fully-known options may be ranked ----
124 let op: *i64 = sys_mmap(8 * EF_O_SLOTS * 8) as *i64
125 let np: i64 = ef_compare(pfx, "partial" as *u8, rid, EG_SCRATCH_MONEY, 1, op, 8)
126 var t5: i64 = 1
127 if np != 4 { t5 = 0 }
128 if op[0 * EF_O_SLOTS + EF_O_KNOWN] != 0 { t5 = 0 } // scratch unknown: a step's pace is unmeasured
129 if ef_unranked(op, np) != 1 { t5 = 0 }
130 if ef_best(op, np) != 1 { t5 = 0 } // prepped, the cheapest FULLY-known option
131 gv_check("T5 the option with an unmeasured step is reported but NEVER ranked; prepped wins the rest" as *u8, t5, ctr)
132
133 // ---- T6 THE HEADLINE: skill flips the recommendation ----
134 let on: *i64 = sys_mmap(8 * EF_O_SLOTS * 8) as *i64
135 let nn: i64 = ef_compare(pfx, "novice" as *u8, rid, EG_SCRATCH_MONEY, 1, on, 8)
136 let oe: *i64 = sys_mmap(8 * EF_O_SLOTS * 8) as *i64
137 let ne: i64 = ef_compare(pfx, "expert" as *u8, rid, EG_SCRATCH_MONEY, 1, oe, 8)
138 var t6: i64 = 1
139 if nn != 4 { t6 = 0 }
140 if ne != 4 { t6 = 0 }
141 if on[0 * EF_O_SLOTS + EF_O_TOTAL] != 4581 { t6 = 0 } // novice scratch: 19.77 + 26.04
142 if oe[0 * EF_O_SLOTS + EF_O_TOTAL] != 2706 { t6 = 0 } // expert scratch: 19.77 + 7.29
143 if on[1 * EF_O_SLOTS + EF_O_TOTAL] != 3100 { t6 = 0 } // prepped: 26.00 + 5.00
144 if on[3 * EF_O_SLOTS + EF_O_TOTAL] != 3600 { t6 = 0 } // restaurant: 36.00 + 0
145 if ef_best(on, nn) != 1 { t6 = 0 } // novice -> BUY IT PREPPED
146 if ef_best(oe, ne) != 0 { t6 = 0 } // expert -> COOK IT
147 gv_check("T6 same dish, same prices: the novice should buy it prepped, the expert should cook it" as *u8, t6, ctr)
148
149 // ---- T7 unvalued time silently makes cooking look free ----
150 let ow: *i64 = sys_mmap(8 * EF_O_SLOTS * 8) as *i64
151 let nw: i64 = ef_compare(pfx, "nowage" as *u8, rid, EG_SCRATCH_MONEY, 1, ow, 8)
152 var t7: i64 = 1
153 if ow[0 * EF_O_SLOTS + EF_O_TIMECOST] != 0 { t7 = 0 }
154 if ow[0 * EF_O_SLOTS + EF_O_TOTAL] != EG_SCRATCH_MONEY { t7 = 0 }
155 if ef_best(ow, nw) != 0 { t7 = 0 } // scratch wins ONLY because time was free
156 if ef_time_is_valued(pfx, "nowage" as *u8) != 0 { t7 = 0 } // ...and the flag says so, so a page must disclose
157 gv_check("T7 with time unpriced, cooking always wins on money alone -- and the flag exposes exactly that" as *u8, t7, ctr)
158
159 let rc: i64 = gv_verdict("MEAL-EFFORT" as *u8, ctr, "skill is a term in the arithmetic; unmeasured pace and unpriced time are disclosed, never assumed" as *u8)
160 sys_exit(rc)
161 return 0
162}