← AI-pair numerics

Tolerance stack: worst case says no, statistics say ship

A board, some standoffs, and a tall capacitor inside an enclosure. Each part is in spec; the question is whether the stack assembles. Worst-case says it might not. Statistics say 99.96% will. Both are right — and knowing which to believe is the job.

1. The brief

A PCB sits on standoffs inside an enclosure, and the tallest component — an electrolytic cap — has to clear the lid. The gap is the enclosure's inner height minus everything stacked under the lid:

gap = Henclosure − (standoff + PCB + component)

Every part carries a tolerance. The requirement is simple — gap ≥ 0, or the lid won't close — but each dimension's ± means the gap is a distribution, not a number. The question isn't “what's the gap”; it's “what fraction of built units assemble.”

2. Why this is an afternoon, not a week

Three standard methods, three lines of math, and Claude runs all three: worst-case (add every tolerance the wrong way), RSS (root-sum-square the tolerances, assuming each is 3σ), and a Monte Carlo (sample thousands of virtual assemblies). The trap is picking one method and trusting it blindly — worst-case over-builds, pure RSS can flatter a sloppy process. The skill is making them agree, and reading the gap between them.

3. The stack

Slide the enclosure height and a global tolerance scale. Watch worst-case, RSS, and the Monte Carlo histogram move together. Red is the interference region (gap < 0).

Monte Carlo — 20,000 virtual assemblies

At the defaults the worst-case minimum gap is −0.20 mm — technically, a build could interfere. Yet RSS and Monte Carlo both put the failure rate near 0.04%: about 1 in 2,700 units. Worst-case isn't wrong; it's improbable. It assumes every one of four parts hits its worst limit in the same direction at the same time — which a real process almost never does.

4. The three methods

Worst-case sums the tolerances linearly: gap = nominal ± Σ|tol|. Guarantees assembly if the min stays ≥ 0, at the cost of demanding tight (expensive) tolerances. RSS sums them in quadrature: ±√(Σ tol²) at 3σ — far less pessimistic, valid when contributors are independent and roughly normal. Monte Carlo samples each dimension and counts failures directly — the referee that confirms RSS, and the only one that copes with skewed or shifted distributions.

5. Verification — the methods must agree

No external answer key. The oracle is internal consistency: three independent methods that have to bracket and confirm one another. When they don't, an assumption broke.

Rung 1 — worst-case bounds everything. The WC range must contain the RSS range, which must contain the Monte Carlo spread.
Pass: WC ⊇ RSS ⊇ MC. If Monte Carlo ever exceeds worst-case, the WC sum is wrong.
Fail here: an MC sample outside the worst-case band means a dropped contributor or a sign error in the stack.
Rung 2 — RSS and Monte Carlo agree on yield. The RSS normal estimate and the MC failure count should match within sampling noise.
Pass: both land near 0.04% interference. Agreement validates the “independent and normal” assumption.
Fail here: if they diverge, your tolerances aren't 3σ, aren't independent, or aren't centered — and pure RSS is lying to you.
Rung 3 — the limits behave. Drive the tolerance scale to zero and all three collapse to the nominal gap; widen it and worst-case fails first.
Pass: methods converge as tolerances shrink and fan out as they grow, in the right order.

6. Hints

Hint 1 — worst-case is a guarantee, not a prediction

A negative worst-case gap doesn't mean “it won't fit” — it means “there exists a combination that won't.” Whether you care depends on volume and the cost of a reject. For one-off aerospace hardware, honor worst-case. For a million consumer units at 0.04% scrap, RSS is the economic answer.

Hint 2 — RSS assumes a lot; check it

RSS treats each tolerance as 3σ of an independent, centered, normal distribution. If a vendor runs to one side of tolerance (mean shift), or two dimensions come off the same mold (correlated), RSS is optimistic. That's exactly why you run Monte Carlo with realistic distributions as the check.

Hint 3 — find the dominant contributor

In RSS, the term that dominates √(Σtol²) is the largest tolerance, squared. Here the ±0.50 cap height swamps everything: 0.50² = 0.25 out of a 0.285 total. Tightening anything else is wasted money; the cap is the lever.

Hint 4 — what to ask for
PromptFor this 1-D stack, compute the gap by worst-case, by RSS (tol = 3σ), and by a 20,000-run Monte Carlo with normal dimensions. Report the WC min/max, the RSS ±3σ and predicted yield, and the MC yield, and confirm WC ⊇ RSS and that RSS≈MC. Then tell me which single tolerance dominates.
Hint — tune the collaborator

Two free levers worth setting. Turn the reasoning effort up for the hard part — Claude Code's /effort (see Feed it documents for the model and effort controls); a transcription wants it low, an analysis like this one wants it high. And end your prompt with an explicit self-check — “before you finish, confirm worst-case bounds RSS and that RSS matches the Monte Carlo yield” — which is exactly why the prompt above asks Claude to verify itself. Naming the oracle is the highest-value line in the prompt. And keep the expensive model's context light — route transcription and formatting to cheaper tools (see Spend tokens well).

7. Where to draw the line

Let Claude run the three methods, the histogram, and the contributor ranking — the arithmetic is mechanical and the cross-checks scale. But you own the judgment that no formula contains: is 0.04% scrap acceptable for this product, are the vendor's parts really centered and normal, is gap ≥ 0 the true requirement or do you need a service margin? The methods agree on the math; only you decide what risk the business will ship.

8. One worked solution

What good looks like

Nominal gap = 20.00 − (5.00 + 1.60 + 12.80) = 0.60 mm. Worst-case half-range = Σtol = 0.15 + 0.05 + 0.10 + 0.50 = 0.80 mm, so WC gap ∈ [−0.20, +1.40]: a possible interference. RSS half-range = √(0.15²+0.05²+0.10²+0.50²) = √0.285 = 0.534 mm (3σ), so RSS gap ∈ [0.07, 1.13], all positive — σgap=0.178, and the nominal sits 3.37σ above zero, i.e. ~0.04% interference. A 20,000-run Monte Carlo lands on the same ~0.04%.

The decision: worst-case would push you to a taller enclosure or a tighter cap spec (the ±0.50 dominates, contributing 0.25 of the 0.285 sum). RSS/MC say a 0.04% reject rate may be cheaper to live with. The analysis can't make that call — but it tells you the cap, not the standoff or the PCB, is the only tolerance worth paying to tighten.

9. Going further

Ship it

Same two moves — see explore in HTML, deliver in PDF.