clear[1]: return 'FAIL_LOOSE', round(max_c,3)\n return 'PASS', (round(min_c,3), round(max_c,3))\n\ndef relative_cost(band): return round((0.10 / max(band,1e-4)), 3)\ndef total_cost(bands): return round(sum(relative_cost(b) for b in bands)/len(bands), 3)","label":"1 — Functional windows + cost model"},{"code":"# Express each band as (low, high) absolute limits in mm.\nbore = (12.010, 12.090) # EDIT band = high-low\nslot = ( 7.980, 8.060) # EDIT\nbore_band = round(bore[1]-bore[0], 3)\nslot_band = round(slot[1]-slot[0], 3)\nbv = fit_verdict(bore[0], bore[1], PIN_MIN, PIN_MAX, BORE_CLEAR)\nsv = fit_verdict(slot[0], slot[1], RIB_MIN, RIB_MAX, SLOT_CLEAR)\nprint(f'bore band={bore_band} -> {bv} cost {relative_cost(bore_band)}x')\nprint(f'slot band={slot_band} -> {sv} cost {relative_cost(slot_band)}x')\nprint('total cost:', total_cost([bore_band, slot_band]), 'x')","label":"2 — Your tolerance bands (EDIT)"},{"code":"np.random.seed(311)\ndef sample_fit(low, high, mate_min, mate_max, clear, n=200):\n dia = np.random.uniform(low, high, n)\n mate = np.random.uniform(mate_min, mate_max, n)\n clr = dia - mate\n return float(np.mean((clr >= clear[0]) & (clr <= clear[1])))\nbore_pass = sample_fit(*bore, PIN_MIN, PIN_MAX, BORE_CLEAR)\nslot_pass = sample_fit(*slot, RIB_MIN, RIB_MAX, SLOT_CLEAR)\nprint(f'bore parts that fit: {bore_pass:.1%} slot: {slot_pass:.1%}')","label":"3 — 200-part Monte-Carlo fit check (seed M3L1=311)"},{"code":"problems = []\nif bv[0] != 'PASS':\n problems.append(f'D1 {bv[0]} — {\"raise the lower limit\" if bv[0]==\"FAIL_TIGHT\" else \"lower the upper limit (loosest passing band = 0.080)\"}.')\nif sv[0] != 'PASS':\n problems.append(f'D3 {sv[0]} — adjust the slot band toward the -0.010..0.110 mm transition window.')\ntc = total_cost([bore_band, slot_band])\nif tc > 1.40:\n problems.append(f'Fit works but total cost {tc}x > 1.40 — each band can open to 0.080 mm (1.25x each); widen toward there.')\n\nif bv[0]=='PASS' and sv[0]=='PASS' and tc <= 1.40:\n print(f'PASS - bore & slot both fit all 200 parts at total cost {tc}x <= 1.40. '\n 'You set a function-driven, cost-aware tolerance - not over-tightened.')\nelse:\n print('FAIL - ' + ' '.join(problems[:2]))","label":"4 — Autograder (seed M3L1, cost gate 1.40x)"}],"intro":"The twin's fit/cost model in numpy: worst-case clearance for the fit verdict, cost ∝ 1/band, total = mean of per-dimension multipliers. Edit your bands and run.","key":"manufacturing/tolerances-the-band-a-part-must-live-in","kind":"python","title":"Tolerances: the band a part must live in"}">
PYTHON · NUMPY · IN-BROWSER

Tolerances: the band a part must live in

The twin's fit/cost model in numpy: worst-case clearance for the fit verdict, cost ∝ 1/band, total = mean of per-dimension multipliers. Edit your bands and run.