Skip to content

Numerical and reproducibility repair

A successful run establishes that one procedure reached an output. It does not yet establish that the implementation is correct, the approximation is converged, correlated data have been analyzed properly, another person can repeat the result, or the underlying scientific model describes the intended regime.

This focused review builds the evidence needed between “it ran” and “the claim is supported.” It uses one deterministic derivative calculation and one correlated-mean calculation, then shows how tests, provenance, and independent checks limit the conclusion you can responsibly draw.

Helpful background. You should be able to distinguish an estimator’s bias from its variance and recognize that correlated observations contain less independent information than equally many independent observations. If that is the main obstacle, begin with Statistical ensembles and probability. No particular programming language is assumed; a calculator, spreadsheet, notebook, or short program is enough.

The word “error” hides mechanisms that respond to different checks. Keep at least these five categories distinct:

SourceTypical causeEvidence that addresses it
Truncation or discretizationReplacing a continuum or infinite process by a finite step, grid, basis, order, or volumeRefinement, observed order, extrapolation, and comparison with a bounded reference case
RoundoffFinite precision, cancellation, overflow, underflow, or poor conditioningPrecision variation, reformulation, conditioning analysis, and scale-aware arithmetic checks
Statistical uncertaintyFinite random data, including autocorrelation and shared inputsCovariance-aware standard errors, effective sample size, blocking or resampling, and repeated streams
Model or systematic errorIncorrect or incomplete physical model, regulator, calibration, fit family, boundary condition, or asymptotic assumptionAlternative models, external calibration, sensitivity studies, held-out observables, and theory arguments
Implementation defectWrong formula, sign, index, units, data handling, or program logicTests that can fail, analytic fixtures, invariants, and independent implementations

An implementation defect is not an uncertainty component to hide inside a wider error bar. Statistical uncertainty usually shrinks with more genuinely independent information; model error generally does not. Truncation can shrink under refinement until roundoff, instability, or computational cost takes over. When several uncertainties are combined, the covariance and the meaning of each component must be stated. Adding unlike quantities in quadrature is not justified merely because each has a percentage attached; the deeper comparison is developed in Complete lattice error budgets.

A convergent calculation with precision turnover

Section titled “A convergent calculation with precision turnover”

Approximate f(1)f'(1) for f(x)=exf(x)=e^x by the central difference

D(h)=e1+he1h2h.D(h) = \frac{e^{1+h}-e^{1-h}}{2h}.

Taylor expansion gives

D(h)=e+e6h2+e120h4+O(h6).D(h) = e+\frac e6h^2+\frac e{120}h^4+\mathcal O(h^6).

In exact arithmetic, the leading truncation error is therefore second order. If E(h)=D(h)eE(h)=\lvert D(h)-e\rvert and the step is reduced by a factor r>1r>1, the observed order is

p(h)=log ⁣(E(h)/E(h/r))logr.p(h) = \frac{\log\!\left(E(h)/E(h/r)\right)}{\log r}.

It should approach 22 only in the range where the h2h^2 term dominates. Here is one typical IEEE binary64 evaluation; the last digits can vary with the math library and evaluation path.

hhD(h)D(h)D(h)e\lvert D(h)-e\rvert
10110^{-1}2.722814563947422.722814563947424.53×1034.53\times10^{-3}
10210^{-2}2.718327133382712.718327133382714.53×1054.53\times10^{-5}
10310^{-3}2.718282281505722.718282281505724.53×1074.53\times10^{-7}
10410^{-4}2.718281832989612.718281832989614.53×1094.53\times10^{-9}
10510^{-5}2.718281828517632.718281828517635.86×10115.86\times10^{-11}
10610^{-6}2.718281828295592.718281828295591.63×10101.63\times10^{-10}
10810^{-8}2.718281821856292.718281821856296.60×1096.60\times10^{-9}
101010^{-10}2.718281155722482.718281155722486.73×1076.73\times10^{-7}

The first four refinements reduce the error by roughly 10210^2 per decade, as predicted. Near h=105h=10^{-5} the trend turns over. The numerator subtracts two nearby floating-point numbers, and division by hh amplifies their rounding error. A useful error model is

E(h)Cth2+Cruh,E(h) \lesssim C_{\mathrm t}h^2 + C_{\mathrm r}\frac{u}{h},

where uu is the unit roundoff and the constants depend on the function and implementation. Balancing these terms predicts an optimal scale of order u1/3u^{1/3}, not the smallest representable positive hh. The exact constants and conditioning still have to be checked Higham 2002, chs. 1–2.

A precision repeat distinguishes the two mechanisms. In exact arithmetic the leading error at h=1010h=10^{-10} is about 4.53×10214.53\times10^{-21}. If an arbitrary-precision evaluation with enough digits approaches that value while binary64 gives an error near 10710^{-7}, the turnover is numerical. Increasing precision should move the turnover to smaller hh. If it does not, investigate the formula, inputs, conditioning, or reference rather than blaming ordinary roundoff.

The derivative routine admits several complementary tests:

  • Exact structural cases. A constant should give zero and a linear function should give its slope, within a tolerance justified by precision.
  • Analytic fixtures. Compare several smooth functions and evaluation points with known derivatives, not only exe^x at one symmetric point.
  • Convergence behavior. Verify the predicted order over a declared range; one close answer at one hh is not a convergence study.
  • Metamorphic or invariant checks. The central formula obeys D(h)=D(h)D(-h)=D(h) when evaluated consistently. A broken symmetry can reveal an argument or sign defect even when no reference value is available.
  • Deliberate defect. Introduce a plausible wrong denominator, shifted index, unit conversion, or sign and confirm that the intended test fails.
  • Independent method. Compare with automatic differentiation, a complex step where applicable, symbolic differentiation, or a separately written finite-difference implementation. Record which assumptions the methods still share.

A tolerance belongs to the test design. Derive it from the analytic error model, precision, conditioning, sampling uncertainty, or a declared external reference before inspecting the result you hope to accept. A test suite can show sensitivity to specified defects; no finite suite proves that every input, regime, or physical model is correct.

Correlated data change the uncertainty, not the estimand

Section titled “Correlated data change the uncertainty, not the estimand”

Let X1,,XNX_1,\ldots,X_N be a stationary sequence with

E[Xi]=μ,Cov(Xi,Xj)=σ2ρij,0ρ<1,\mathbb E[X_i]=\mu, \qquad \operatorname{Cov}(X_i,X_j) = \sigma^2\rho^{\lvert i-j\rvert}, \qquad 0\leq\rho<1,

and estimate the stationary mean by

X=1Ni=1NXi.\overline X=\frac1N\sum_{i=1}^N X_i.

Linearity gives E[X]=μ\mathbb E[\overline X]=\mu, so the common-mean estimator is unbiased under the stated assumptions. Correlation changes its variance:

Var(X)=σ2N2[N+2k=1N1(Nk)ρk].\operatorname{Var}(\overline X) = \frac{\sigma^2}{N^2} \left[ N+2\sum_{k=1}^{N-1}(N-k)\rho^k \right].

For large NN at fixed ρ\rho,

Var(X)σ2N1+ρ1ρ,NeffN1ρ1+ρ.\operatorname{Var}(\overline X) \sim \frac{\sigma^2}{N} \frac{1+\rho}{1-\rho}, \qquad N_{\mathrm{eff}} \sim N\frac{1-\rho}{1+\rho}.

Take a concrete marginal variance σ2=1\sigma^2=1, N=1000N=1000, and ρ=0.8\rho=0.8. The independent-sample formula gives

SEnaive=110000.0316.\operatorname{SE}_{\mathrm{naive}} = \frac1{\sqrt{1000}} \approx0.0316.

The exact finite-NN covariance sum instead gives

Var(X)=0.00896,SE(X)0.0947,Neff111.6.\operatorname{Var}(\overline X)=0.00896, \qquad \operatorname{SE}(\overline X)\approx0.0947, \qquad N_{\mathrm{eff}}\approx111.6.

The naive standard error is too small by nearly a factor of three. If this standard error is turned into a confidence or credible interval, the sampling distribution or posterior model and the intended coverage or probability interpretation must also be stated. For a sequence generated as a stationary AR(1) process Xt=0.8Xt1+εtX_t=0.8X_{t-1}+\varepsilon_t, unit marginal variance requires Var(εt)=10.82=0.36\operatorname{Var}(\varepsilon_t)=1-0.8^2=0.36; setting the innovation variance to one defines a different example.

In real data, ρ\rho and the covariance tail are unknown. Estimate them with a stated window, batch means, blocking, or another justified time-series method, and test stability as that choice changes. A stable sample mean alone does not establish stationarity or equilibration. Nor does the standard error include model bias, initialization bias, or uncertainty in a physical calibration. The correlation-aware variance framework is developed in Sokal 1997, pp. 131–192 and the practical window tradeoff in Wolff 2004, pp. 143–153. For deeper study, continue to Autocorrelation times and effective sample size.

Reproducibility is not a property of the final number alone. It is a relation between a specified target, procedure, inputs, environment, outputs, and acceptance rule. Terminology differs across fields, so define the independence you actually tested:

CheckWhat is held fixedWhat it can reveal
RerunSame method, implementation, inputs, and intended environmentMissing instructions, unstable dependencies, nondeterminism, or failure to execute again
ReanalysisSame raw data or stored outputs, but a new analysis implementation or defensible analysis choicesAnalysis-code defects and sensitivity to downstream choices; it does not test data generation
Independent reproductionA separately written implementation and, when relevant, independently regenerated data from the mathematical and scientific specificationShared-code defects and some generation failures; it can still share a wrong model or reference formula

These definitions are operational; report overlaps in code, libraries, data, calibration, formulas, and analyst choices. Broader terminology and its limits are discussed by National Academies 2019, ch. 3.

For a small result, the following plain-text packet is enough to expose most missing information:

question, estimand, and scientific regime:
formula, model, or source specification:
exact inputs, units, preprocessing, and checksums:
source revision and dependency versions:
platform, numeric type, and precision:
run command or ordered interaction steps:
tolerances, stopping rules, and failure behavior:
random generator, stream construction, and seed policy:
raw outputs, logs, and checksums:
analysis choices and changes made after seeing results:
expected tests, convergence model, and acceptance rule:
claim supported by this packet—and claims not tested:

A seed without the generator and stream construction is incomplete. A dependency lock without the inputs is incomplete. A notebook that depends on hidden execution order is incomplete. A checksum identifies bytes but does not explain what they mean. Test the packet by using it in a clean environment or handing it to another analyst, then add every missing step that had to be guessed. For a fuller treatment of independence, see Blinding, analysis choices, and independent reproduction.

Keep the scientific claim within the evidence

Section titled “Keep the scientific claim within the evidence”

Different statements require different evidence:

StatementMinimum supporting evidenceWhat remains outside it
The procedure executedRecorded environment, command, inputs, and outputCorrectness and scientific meaning
The implementation passed specified testsExpected results, justified tolerances, and tests shown to detect intended defectsUntested inputs and shared defects
The numerical target is verified in a tested regimeReference fixture, convergence and precision studies, and independent checksExtrapolation beyond the tested regime
The estimator has the quoted uncertaintyEstimand, dependence model, covariance-aware analysis, and interval assumptionsModel bias and unmeasured systematics
The scientific conclusion is supportedAll preceding evidence plus a justified physical model, observable, regulator or continuum argument, calibration, and systematic-error analysisClaims outside the declared theory and regime

Agreement between two implementations can verify a bounded numerical target while both implement the same wrong physical model. More samples can narrow a Monte Carlo standard error while leaving finite-volume, cutoff, fit-model, or calibration errors unchanged. A sensitivity envelope is not automatically a probability distribution, and an independent reproduction is a test, not a new uncertainty term to add mechanically.

1. Locate convergence and choose a robust test point

Section titled “1. Locate convergence and choose a robust test point”

Using the derivative table, compute the observed order for the refinements 10110210^{-1}\to10^{-2} and 10210310^{-2}\to10^{-3}. What happens for 10510610^{-5}\to10^{-6}? Choose a robust binary64 step and justify a test tolerance.

Solution

For decade refinement, r=10r=10. The first two estimates are

p(101)=log10 ⁣(4.53×1034.53×105)2,p(102)=log10 ⁣(4.53×1054.53×107)2.\begin{aligned} p(10^{-1}) &=\log_{10}\!\left( \frac{4.53\times10^{-3}}{4.53\times10^{-5}} \right) \approx2,\\ p(10^{-2}) &=\log_{10}\!\left( \frac{4.53\times10^{-5}}{4.53\times10^{-7}} \right) \approx2. \end{aligned}

For 10510610^{-5}\to10^{-6}, the error increases from about 5.86×10115.86\times10^{-11} to 1.63×10101.63\times10^{-10}, so the observed order is negative. The calculation has left the truncation-dominated range.

Although h=105h=10^{-5} happens to give the smallest error in this table, it is near the turnover and can be sensitive to evaluation details. A more robust fixture is h=104h=10^{-4}, where the expected truncation error is about 4.53×1094.53\times10^{-9} and second-order behavior is still clear. A tolerance of order 10810^{-8} is defensible for this stated platform and formula after the preceding refinement and precision checks. It is not a universal tolerance for every implementation or function.

For the covariance model with N=1000N=1000, ρ=0.8\rho=0.8, and σ2=1\sigma^2=1, compute the large-NN effective sample size and standard error. Compare them with the independent-sample values and explain what additional checks real data require.

Solution

The large-NN effective sample size is

Neff100010.81+0.8=111.1.N_{\mathrm{eff}} \sim 1000\frac{1-0.8}{1+0.8} = 111.1.

Thus

SE(X)1111.10.0949,\operatorname{SE}(\overline X) \approx \frac1{\sqrt{111.1}} \approx0.0949,

whereas the independent formula gives Neff=1000N_{\mathrm{eff}}=1000 and SE=0.0316\operatorname{SE}=0.0316. Correlation has reduced the information by about a factor of nine and increased the standard error by about a factor of three. The exact finite-NN values are Neff111.6N_{\mathrm{eff}}\approx111.6 and SE0.0947\operatorname{SE}\approx0.0947.

Real data require evidence for equilibration or stationarity, an estimated autocorrelation tail or block length, stability under reasonable window or block changes, and enough independent streams or history to expose slow modes. The algebra with known ρ\rho does not supply those checks.

Classify each case and state what it does not test:

  1. A colleague uses the recorded command, same source, same inputs, and locked dependencies on a clean machine.
  2. A second analyst receives the same raw output but writes a new fitting script and varies the justified fit window.
  3. A separate group implements the published algorithm from the mathematical specification and regenerates the synthetic data with an independent random stream.
Solution

The first is a rerun. It tests whether the preserved procedure and environment description are sufficient and exposes some dependency or nondeterminism problems. It shares the implementation, inputs, and model, so it does not test code defects or data generation.

The second is a reanalysis. It tests downstream analysis code and fit-window sensitivity. It still shares the raw data and every upstream generation or measurement defect.

The third is an independent reproduction with both implementation and synthetic generation independence. It adds strong protection against shared code and random-stream defects. The groups can nevertheless agree because they share the same incorrect mathematical specification or scientific model, so agreement alone does not establish a physical conclusion.

A result quotes a 1.2%1.2\% correlation-aware statistical error, a 0.8%0.8\% discretization estimate, a shared 0.5%0.5\% calibration uncertainty, and a 3%3\% spread across defensible physical models. May these four percentages be added in quadrature automatically? Which component is reduced by generating four times as much effectively independent data?

Solution

No. Quadrature represents the variance of a sum only under an appropriate probabilistic model with the relevant covariances. The statistical term may have such an interpretation. The discretization number might be a bound or an extrapolation sensitivity; the calibration can be shared across all samples; and the model spread is not automatically a random variable with known coverage. Each needs its own meaning and dependence structure before any combination.

Four times as much effectively independent data reduces the statistical standard error by a factor of two, from 1.2%1.2\% to about 0.6%0.6\%. It does not automatically reduce the discretization, calibration, or model components. Those require refinement, better calibration, alternative observables or models, and scientific validation.

Repeat the computational and evidence diagnostic with a numerical integral whose exact value is known and a newly generated correlated sequence. Your result is ready to carry forward when it contains:

  • a precise target, units, regime, and bounded reference case;
  • tests that demonstrably fail under at least one plausible defect;
  • a refinement study with an observed order and a precision repeat;
  • correlation-aware uncertainty and its stationarity or equilibration assumptions;
  • a complete reproducibility packet tested in a clean rerun or independent analysis;
  • explicit shared dependencies for every repeat; and
  • separate execution, numerical-verification, uncertainty, and scientific claims, with unsupported claims marked as such.

If all seven elements are explicit, continue to Computational field theory onboarding or Reproduce and validate a result. If only the covariance analysis remains weak, return to Statistical ensembles and probability and repeat the correlated-mean exercise with a new value of ρ\rho. If the refinement or precision behavior is unexplained, do not enlarge the tolerance; isolate the deterministic calculation before attaching it to a scientific result.

  • Nicholas J. Higham, Accuracy and Stability of Numerical Algorithms, second edition, Society for Industrial and Applied Mathematics, 2002, doi:10.1137/1.9780898718027.
  • National Academies of Sciences, Engineering, and Medicine, Reproducibility and Replicability in Science, National Academies Press, 2019, doi:10.17226/25303.
  • Alan D. Sokal, “Monte Carlo Methods in Statistical Mechanics: Foundations and New Algorithms,” in Cécile DeWitt-Morette, Pierre Cartier, and Antoine Folacci, eds., Functional Integration: Basics and Applications, Springer, 1997, pp. 131–192, doi:10.1007/978-1-4899-0319-8_6.
  • Ulli Wolff, “Monte Carlo Errors with Less Errors,” Computer Physics Communications 156 (2004): 143–153, doi:10.1016/S0010-4655(03)00467-3.