This page summarizes the mathematics and the concrete outputs produced by the current DataLab implementation (source-of-truth = code behavior).
All core computations use mpmath (mp.mpf) with a configurable mp.dps (decimal digits of precision).
- Parentheses notation:
value(digits)[exp]
1.2345(67)means1.2345 ± 0.00671.2345(67)[-2]means(1.2345 ± 0.0067) × 10^-2
- Separate σ column: provide a dedicated
sigmacolumn (or pick it in the UI).
Column headers are normalized into safe identifiers (non-alphanumerics → _, leading digit → prefixed). Legacy aliases:
- Error propagation:
x1/x2/...are rewritten to canonical column symbols. - Custom extrapolation: supports headers,
x1/x2/..., plusA/B/Cfor the first three columns.
All three custom-expression features reuse the same parser and the same whitelist: data_extrapolation_latex_latest.py:safe_eval.
- Allowed: numeric literals, variables, parentheses,
+ - * / ** %, unary+/-, and calls to whitelisted functions. - Mathematica-style is supported:
Sin[x]([]auto →()),^auto →**. - Forbidden: attribute access (
a.__class__), keyword arguments, string/object constants, and any non-whitelisted AST nodes.
Constants (case-sensitive): Pi, E
Functions (capitalized):
- Basics:
Sin,Cos,Tan,Asin,Acos,Atan,Sinh,Cosh,Tanh,Asinh,Acosh,Atanh - Exp/Log:
Exp,Log,Ln,Log10,Sqrt,Power - Common:
Abs,Erf,Gamma - Special:
Zeta,Hyp0f1,Hyp1f1,Hyp2f1,PolyLog,BesselJ,BesselY,Airy
For each data row, extrapolation produces an extrapolated value V, an uncertainty estimate U, plus method metadata.
Given A,B,C:
V = ((C - B)^2) / (B - A) + CU = max(|V-A|, |V-B|, |V-C|)
Model: E(x) = E_inf + a * x^(-p)
Given (E1,E2,E3) and (x1,x2,x3):
R = (E1-E2)/(E2-E3)- Solve
(x1^{-p}-x2^{-p})/(x2^{-p}-x3^{-p}) = Rforp a = (E1-E2)/(x1^{-p}-x2^{-p})E_inf = E1 - a*x1^{-p}
Backed by mpmath routines and returning extra metadata (e.g. error estimates).
For power_law / accelerators / custom:
U = |V - reference|
The reference column defaults to the 3rd column; auto_max_diff can pick the column that maximizes |V - col_i| for a conservative U.
Per-row fields:
value(V),uncertainty(U),methoddetails(e.g.reference_column, power-lawexponent/amplitude, accelerator metadata, customformula)
For each row of uncertain inputs, compute f(x) and propagate σ.
σ_f = sqrt( Σ ( ∂f/∂x_i * σ_i )^2 )
For order=2, the implementation adds Hessian (second-derivative) contributions and applies a mean correction to the reported value (closer to Monte Carlo mean):
E[f] ≈ f(μ) + 1/2 * Σ_i (∂²f/∂x_i²) * σ_i²Var[f] ≈ Σ_i (∂f/∂x_i)² σ_i² + 1/2 * tr((H Σ)²)
Here H is the Hessian and Σ is the input covariance matrix; the current implementation assumes diagonal Σ (independent inputs).
The implementation tries symbolic differentiation (Sympy) first, and falls back to numerical finite differences when needed.
Numerical partials use central differences:
∂f/∂x ≈ (f(x+h) - f(x-h)) / (2h)
The step size h is adaptive with mp.dps (rule of thumb: order-1 h ~ eps^(1/3), order-2 h ~ eps^(1/4), scaled by max(1,|x|)), balancing truncation and rounding errors.
An AST scan detects which columns/constants are actually referenced; only those are used for propagation (fallback = use all on parse failure).
Per-row:
value:- Taylor
order=1:f(μ)at the working point - Taylor
order=2:≈ E[f](with mean correction) - Monte Carlo: sample mean
- Taylor
uncertainty: standard uncertainty (standard deviation)- optional
contributions(variance contributions per input)
Fit (x_i, y_i) to a model and report parameters, uncertainties, covariance, and goodness-of-fit metrics.
Residuals: r_i = y_model(x_i; p) - y_i
- Unweighted:
χ² = Σ r_i^2 - Weighted:
χ² = Σ w_i r_i^2(typicalw_i = 1/σ_i^2)
dof = n - k (n points, k free parameters).
Linear-in-parameters form y ≈ Σ b_j φ_j(x) solved via QR least squares (weighted by scaling rows with sqrt(w_i) when applicable).
Custom model expressions are parsed via fitting/model_parser.py:build_model_specification:
- Evaluation uses the same
safe_evalas extrapolation/error-propagation. - Parameter partials are numerical (central difference).
- Optimization solves
∂χ²/∂p_j = 0usingmp.findroot, trying multiple seed variants.
Templates:
- Power-law limit:
A*x**(-p) + C(constraintp ≥ 0.1) - Padé(m|n):
(a0 + a1 x + ... + a_m x^m) / (1 + b1 x + ... + b_n x^n)
Near the optimum, approximate:
- Jacobian
J_{i,j} = ∂y_model/∂p_jat the solution (rows scaled bysqrt(w_i)if weighted) Cov ≈ (J^T J)^{-1} * σ², withσ² ≈ χ²/dof- Parameter standard errors:
σ(p_j) = sqrt(Cov_{j,j})
Singular/ill-conditioned cases trigger warnings and NaN uncertainties.
params,param_errors_stat/sys/total(and compatibilityparam_errors)covariance,residuals,fitted_curve- metrics:
chi2,reduced_chi2,aic,bic,r2,rmse details: expression, weighted flag, boundary/covariance warnings, etc.
Implementation note (current code):
- Desktop: “statistical weighting” builds
w=1/σ²for weighted χ²/covariance, and does not add a separate systematic term (to avoid double counting). - Web: the current
fit_weightedflag feeds σ into ±σ refits (systematic estimate) and does not apply weighted χ².
Arithmetic/weighted means with optional σ:
- Mean, standard deviation (sample/population), standard error, min/max
- Weighted mean uses
w=1/σ^2, and may report effectiven_eff = (Σw)^2/Σ(w^2)
All modules can format results in parentheses notation and generate:
- CSV
- LaTeX tables (optionally aligned via
dcolumn/siunitx) - optional PDF compilation in supported environments