manufacturing.yield-scrap
Whole units to start for a required good output at a process yield, and the scrap that allows for.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 15 tests, run in TypeScript, Python and Rust.
What it does
How many units to start so that, at a process yield, enough good units come out:
input = ceil(requiredOutput / yield) scrap = input - requiredOutput
For example
input_for_yield(100, 95%)→ input 106, scrap 6 100 good units at 95% need 105.26, so 106 starts and 6 allowed as scrapinput_for_yield(95, 95%)→ input 100, scrap 5 95 good units at 95% need exactly 100 startsinput_for_yield(563, 56.3%)→ input 1,000, scrap 437 563 good units at 56.3% need exactly 1000 starts; 563 / 0.563 in floating point is 1000.0000000000001, whose ceiling is 1001
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
def input_for_yield(required_output: int, yield_basis_points: int) -> YieldPlan
| required_output | int | good units needed, not negative |
| yield_basis_points | int | good output as a share of input: 9500 = 95%, 1 to 10000 |
| returns | YieldPlan |
The type it declares, generated into your project
@dataclass(frozen=True)
class YieldPlan:
"""What to start and what the process is expected to lose."""
#: units to start: the smallest whole number whose yield covers requiredOutput
input: int
#: input minus requiredOutput: the units the yield allows to be lost
scrap: int
Your code names it in one line, in the file that uses it
from fune.manufacturing.yield_scrap import input_for_yield # manufacturing.yield-scrap@^1
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
from .manufacturing_yield_scrap_types import YieldPlan
from .math_round_div import round_div ← from math.round-div ^1.0.0 · built alongside by fune
MAX_OUTPUT = (2**53 - 1) // 10000
def input_for_yield(required_output: int, yield_basis_points: int) -> YieldPlan:
"""Starts needed for a good output at a yield, rounded up in integers so an
exact answer (95 at 95% is 100) never becomes 101 through a float.
"""
if (
isinstance(required_output, bool)
or not isinstance(required_output, int)
or required_output < 0
or required_output > MAX_OUTPUT
):
raise ValueError(
"requiredOutput must be a whole number of units from 0 to %d, received %r" % (MAX_OUTPUT, required_output)
)
if (
isinstance(yield_basis_points, bool)
or not isinstance(yield_basis_points, int)
or yield_basis_points < 1
or yield_basis_points > 10000
):
raise ValueError("yieldBasisPoints must be a whole number from 1 to 10000, received %r" % (yield_basis_points,))
input_units = round_div(required_output * 10000, yield_basis_points, "up")
return YieldPlan(input=input_units, scrap=input_units - required_output)Install
fune build
With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add manufacturing.yield-scrap
The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./manufacturing.yield-scrap-1.0.0-python.fune, or fetch it from a terminal with fune pull manufacturing.yield-scrap@1.0.0:python.
The whole function, every language, is one file too: manufacturing.yield-scrap-1.0.0.fune, 9,473 bytes, sha256 ab5b9cd98e14ed85a740cf8e559162cb6e2553b2573427c955d5584c4f4351aa. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
# fune: before manufacturing.yield-scrap
after — your function gets the result and the arguments, and returns the final result.
# fune: after manufacturing.yield-scrap
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
# fune: replace math.round-div in manufacturing.yield-scrap
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show manufacturing.yield-scrap --steps.
# fune: step manufacturing.yield-scrap after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| 100 good units at 95% need 105.26, so 106 starts and 6 allowed as scrap | 100, 95% | → | input 106, scrap 6 |
| 95 good units at 95% need exactly 100 starts | 95, 95% | → | input 100, scrap 5 |
| 563 good units at 56.3% need exactly 1000 starts; 563 / 0.563 in floating point is 1000.0000000000001, whose ceiling is 1001 | 563, 56.3% | → | input 1,000, scrap 437 |
| 57 at 90% need 63.33, so 64 | 57, 90% | → | input 64, scrap 7 |
| a 100% yield needs no allowance | 250, 100% | → | input 250, scrap 0 |
| a tiny shortfall still costs a whole start: 1000 at 99.99% need 1000.1, so 1001 | 1,000, 99.99% | → | input 1,001, scrap 1 |
| one good unit at 30% needs 3.33, so 4 starts | 1, 30% | → | input 4, scrap 3 |
| the lowest yield, 0.01%: one good unit needs 10000 starts | 1, 0.01% | → | input 10,000, scrap 9,999 |
| zero output needs no input | 0, 80% | → | input 0, scrap 0 |
| a 50% yield doubles the input exactly | 37, 50% | → | input 74, scrap 37 |
Show the other 5 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| a zero yield is an error: nothing good ever comes out | 100, 0% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
| a yield over 100% is an error | 100, 100.01% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
| a negative output is an error | -5, 95% | → | error: requiredOutput must be a whole number of units |
| a fractional output is an error | 10.5, 95% | → | error: requiredOutput must be a whole number of units |
| a fractional yield is an error | 100, 95.005% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
More from the author
With a 95% yield, 100 good units need 106 starts (105.26 rounded up), and the plan allows 6 to be scrapped.
**Rounded up, exactly.** You cannot start part of a unit, and rounding down would leave you short, so the input is always rounded up. The division is done in integers (`requiredOutput * 10000 / yieldBasisPoints`, rounded up by `math.round-div`), never as a float: 563 good units at a 56.3% yield need exactly 1000 starts, but `563 / 0.563` in floating point is 1000.0000000000001, and its ceiling is 1001.
**Scrap is the allowance.** At the stated yield, `input` starts are expected to give at least `requiredOutput` good units and fewer than `requiredOutput + 1` (the rounding never buys a whole extra unit), so `scrap` is the whole number of units the plan expects to lose. The actual scrap is whatever the process does on the day.
**Yield is in basis points**, 1 to 10000 (0.01% to 100%). A yield of 0 is an error: no number of starts gives any good output. A required output of 0 needs no input.
For a routing with several steps, apply this from the last step backwards: the input of one step is the required output of the one before, rounded up at each step, because each step has to start whole units.
Files
| Path | Bytes |
|---|---|
| README.md | 1,408 |
| impl/python.py | 1,163 |
| impl/rust.rs | 1,549 |
| impl/typescript.ts | 1,003 |
| vectors.json | 2,046 |