code wiki / (root) / nx_ferment_cultures.nx

nx_ferment_cultures.nx source

↩ module page · 153 lines · 5005 B

1// nx_ferment_cultures.nx -- R6b: the CONVERGENCE rung. Binds the R4 2// ferment recipe catalog (yogurt/cheese/kraut/...) to the R6 cross- 3// kingdom beneficial-microbe engine, so the cheese/yogurt maker KNOWS 4// which beneficial bacteria each ferment cultivates and what health 5// opportunities they confer -- and can PROVE every declared culture is 6// safe to eat. 7// 8// THE EXCEED: a yogurt maker holds temperature; a recipe card names a 9// starter. Neither can prove the starter is a safe, characterized 10// organism. Here every ferment's declared cultures are validated 11// through the R6 never-HARM gate for the HUMAN host (you eat a ferment), 12// so a recipe can NEVER ship a pathogen or an antibiotic-resistant 13// opportunist as its "culture" (liar-killed by the gate). 14// 15// HONEST GAPS (never fabricated): kombucha (acetic-acid bacteria) and 16// tempeh (Rhizopus mold) are not yet in the bacterial catalog -> they 17// declare 0 cultures rather than a made-up entry. 18// 19// genealogy_id: nishi_ferment_recipes_r4 + nishi_probiome_r6 20 21import "nx_syscalls.nx" 22import "nx_ferment_recipes.nx" 23import "nx_probiome.nx" 24 25const FC_MAX_CULTURES: i64 = 4 26 27// Up to 4 culture strain ids per recipe held as scalar fields (avoids 28// the call-in-array-store SEGV gotcha; -1 = empty slot). 29struct NxFermentCultures { 30 recipe_id: i64, 31 count: i64, 32 s0: i64, 33 s1: i64, 34 s2: i64, 35 s3: i64, 36} 37 38func nx_ferment_cultures(recipe_id: i64) -> *NxFermentCultures { 39 let c: *NxFermentCultures = (sys_mmap(64)) as *NxFermentCultures 40 c.recipe_id = recipe_id 41 c.count = 0 42 c.s0 = -1 43 c.s1 = -1 44 c.s2 = -1 45 c.s3 = -1 46 // Yogurt: Streptococcus thermophilus + Lactobacillus acidophilus. 47 if recipe_id == NX_RCP_YOGURT { 48 c.count = 2 49 c.s0 = PB_STR_S_THERMOPHILUS 50 c.s1 = PB_STR_L_ACIDOPHILUS 51 } 52 // Soft + aged cheese: Lactococcus lactis (the mesophilic cheese starter). 53 if recipe_id == NX_RCP_CHEVRE { 54 c.count = 1 55 c.s0 = PB_STR_L_LACTIS 56 } 57 if recipe_id == NX_RCP_CHEDDAR { 58 c.count = 1 59 c.s0 = PB_STR_L_LACTIS 60 } 61 // Vegetable ferments: lactic-acid bacteria (L. acidophilus stands for 62 // the wild Lactobacillus that sours kraut/kimchi). 63 if recipe_id == NX_RCP_SAUERKRAUT { 64 c.count = 1 65 c.s0 = PB_STR_L_ACIDOPHILUS 66 } 67 if recipe_id == NX_RCP_KIMCHI { 68 c.count = 1 69 c.s0 = PB_STR_L_ACIDOPHILUS 70 } 71 // Kombucha SCOBY: acetic-acid bacteria + yeast symbiosis. 72 if recipe_id == NX_RCP_KOMBUCHA { 73 c.count = 2 74 c.s0 = PB_STR_ACETOBACTER 75 c.s1 = PB_STR_S_CEREVISIAE 76 } 77 // Tempeh: knit together by the Rhizopus oligosporus mold. 78 if recipe_id == NX_RCP_TEMPEH { 79 c.count = 1 80 c.s0 = PB_STR_RHIZOPUS 81 } 82 return c 83} 84 85func fc_culture_at(c: *NxFermentCultures, i: i64) -> i64 { 86 if i == 0 { return c.s0 } 87 if i == 1 { return c.s1 } 88 if i == 2 { return c.s2 } 89 if i == 3 { return c.s3 } 90 return -1 91} 92 93// Every declared culture must ADMIT through the never-HARM gate for the 94// HUMAN host -- you eat a ferment. Returns the first refusal verdict, or 95// PB_OK if all cultures are safe (0 cultures = uncharacterized, not unsafe). 96func fc_cultures_safe(c: *NxFermentCultures) -> i64 { 97 var i: i64 = 0 98 while i < c.count { 99 let sid: i64 = fc_culture_at(c, i) 100 let s: *NxProbiomeStrain = nx_probiome_strain(sid) 101 let v: i64 = nx_probiome_admit(s, PB_HOST_HUMAN) 102 if v != PB_OK { return v } 103 i = i + 1 104 } 105 return PB_OK 106} 107 108// Aggregate host-benefit mask across a recipe's cultures. 109func fc_recipe_host_mask(recipe_id: i64) -> i64 { 110 let c: *NxFermentCultures = nx_ferment_cultures(recipe_id) 111 var mask: i64 = 0 112 var i: i64 = 0 113 while i < c.count { 114 let sid: i64 = fc_culture_at(c, i) 115 let s: *NxProbiomeStrain = nx_probiome_strain(sid) 116 mask = mask | s.host_mask 117 i = i + 1 118 } 119 return mask 120} 121 122func fc_recipe_benefits_host(recipe_id: i64, host: i64) -> i64 { 123 if host < 0 { return 0 } 124 if host >= PB_HOST_N { return 0 } 125 let mask: i64 = fc_recipe_host_mask(recipe_id) 126 let bit: i64 = 1 << host 127 if (mask & bit) != 0 { return 1 } 128 return 0 129} 130 131// Aggregate benefit-mechanism mask -- what health mechanisms the ferment 132// delivers via its live cultures. 133func fc_recipe_mech_mask(recipe_id: i64) -> i64 { 134 let c: *NxFermentCultures = nx_ferment_cultures(recipe_id) 135 var mask: i64 = 0 136 var i: i64 = 0 137 while i < c.count { 138 let sid: i64 = fc_culture_at(c, i) 139 let s: *NxProbiomeStrain = nx_probiome_strain(sid) 140 mask = mask | s.mechanism_mask 141 i = i + 1 142 } 143 return mask 144} 145 146func fc_recipe_delivers(recipe_id: i64, mech: i64) -> i64 { 147 if mech < 0 { return 0 } 148 if mech >= PB_MECH_N { return 0 } 149 let mask: i64 = fc_recipe_mech_mask(recipe_id) 150 let bit: i64 = 1 << mech 151 if (mask & bit) != 0 { return 1 } 152 return 0 153}