code wiki / (root) / nx_caplab_products.nx

nx_caplab_products.nx source

↩ module page · 47 lines · 1887 B

1// nx_caplab_products.nx -- Capitalism Lab R5: multiple products + categories. 2// 3// A firm sells a PORTFOLIO of products across separate category markets (Soda, 4// Shoes, Phones...). Each category is its OWN market (own choke price + size); 5// firms compete within it by price/quality/brand (R4 split); a firm's total 6// profit sums its products. Categories are INDEPENDENT -- dominating Soda does 7// not change the Shoes market. Composes R3 (capacity) + R4 (quality/brand). 8// 9// nx_safety_envelope: 10// intended_use: capitalism-lab product portfolio (pure functions, no I/O) 11// sil_target: SIL1 12// verdict: NOT_YET_EVALUATED 13// 14// genealogy_id: capitalism_lab_products_categories_canon 15// lineage_id: nx_caplab_products_v1 16 17import "nx_syscalls.nx" 18import "nx_tier.nx" 19import "nx_caplab_quality.nx" 20 21// Run one category market: split demand by quality/brand/price appeal, then cap 22// each firm's sales by its capacity in that category. 23func nx_clab_category_run(n_firms: nx_int, prices: *i64, quals: *i64, brands: *i64, 24 choke: nx_int, wp: nx_int, wq: nx_int, wb: nx_int, 25 market_m: nx_int, caps: *i64, out_sold: *i64) { 26 nx_clab_split_qb(n_firms, prices, quals, brands, choke, wp, wq, wb, market_m, out_sold) 27 var i: nx_int = 0 28 while i < n_firms { 29 if out_sold[i] > caps[i] { out_sold[i] = caps[i] } 30 i = i + 1 31 } 32} 33 34func nx_clab_product_profit(price: nx_int, unit_cost: nx_int, sold: nx_int) -> nx_int { 35 return (price - unit_cost) * sold 36} 37 38// A firm's total profit across its product line (the portfolio). 39func nx_clab_portfolio_profit(n_products: nx_int, prices: *i64, costs: *i64, solds: *i64) -> nx_int { 40 var total: nx_int = 0 41 var i: nx_int = 0 42 while i < n_products { 43 total = total + (prices[i] - costs[i]) * solds[i] 44 i = i + 1 45 } 46 return total 47}