Mathematical Foundations

VIII.3 · Numerical Computing

When does a tiny input change cause a large output change?

Perturb a known function and inspect its exact response. Keep problem conditioning, algorithm stability, floating-point roundoff and the error of one answer as separate questions.

Perturb the input and track distinct errors

Mathematical function

Square: well-conditioned at nonzero x. Relative condition number 2. Representation effect, arithmetic roundoff and total answer error are separate exact rational differences.

Exact mathematical reference
4
Exact perturbed reference
40401/10000
Exact output change
401/10000
Local relative condition number
2
Stored input
2
Computed binary64 answer
4
Effect of input representation
0
Actual evaluation roundoff
0
Total answer error
0

= exact rationals or classifications · ≈ a formatted numerical display. Exceptional values retain their stated meaning.

f(x)=x2,κf(x)=2 (x≠0)f(x)=x^2,\quad\kappa_f(x)=2\ (x\ne0)
E=(f(x^)−f(x))+(f^−f(x^))E=\bigl(f(\widehat x)-f(x)\bigr)+\bigl(\widehat f-f(\widehat x)\bigr)
Exact intended input versus actual stored input.
inputexact referencebinary64 inputbinary64 output
24≈ 2≈ 4
201/10040401/10000≈ 2.00999999999999979≈ 4.04009999999999891

Exact problem

Evaluate the chosen mathematical function on the intended rational input.

Inspect the recorded values\text{Inspect the recorded values}
Actual intermediate values; = exact rationals, ≈ binary64 displays.
quantityvalue
input2
reference4

Exact decimal text, at most 420 characters; exponent in [-400,400].

|perturbation| ≤ 1.

Change the exact input and perturbation; compare the mathematical response with input representation, actual evaluation roundoff and total answer error.

Intuition: sensitivity belongs to a question

A measurement can be almost unchanged while the mathematical answer changes substantially. That sensitivity exists before selecting any computer algorithm. The reciprocal example asks for 1/(x−1)1/(x-1) close to x=1; a tiny change in the denominator can halve or double the answer.

The square example at x=2 provides a well-conditioned contrast. The relative size of a small output perturbation is approximately twice the relative size of the input perturbation. A large absolute output alone is not a condition number: units and scales matter.

Definition: local relative conditioning

For a differentiable scalar function with nonzero x and nonzero f(x), a local relative condition number is

κf(x)=∣xf′(x)f(x)∣.\kappa_f(x)=\left|\frac{x f'(x)}{f(x)}\right|.

It comes from the first-order response Δf≈f′(x)Δx\Delta f\approx f'(x)\Delta x, and therefore describes infinitesimal perturbations at a valid point. It is not an unconditional bound for arbitrary finite changes. At zero output this relative definition is undefined; absolute sensitivity ∣f′(x)∣|f'(x)| can still be meaningful.

For f(x)=x2f(x)=x^2, the nonzero-input relative condition number is 2. For f(x)=1/(x−1)f(x)=1/(x-1) with x≠1, it is ∣x/(x−1)∣|x/(x-1)|. At x=0 the reciprocal value is nonzero but the usual relative-input interpretation degenerates; the displayed analytic formula evaluates to zero, and should not be read as a guarantee for relative perturbations of zero.

Mechanics: four distinct quantities

Conditioning describes how the mathematical problem responds to input changes. Stability describes how an algorithm’s errors relate to nearby valid problems or to a suitable error bound. Roundoff describes the actual error introduced by finite arithmetic. Answer error compares one computed answer with the specified mathematical answer.

The explorer keeps exact decimal x and delta, exact f(x) and f(x+delta), the binary64 stored input, and the computed answer. It splits answer error into input representation effect and arithmetic evaluation roundoff. This split uses exact rational values for the two supported functions; it does not classify an algorithm as stable merely because one displayed error is small.

Derivation: perturbation and representation

For the square,

f(x+δ)−f(x)=2xδ+δ2.f(x+\delta)-f(x)=2x\delta+\delta^2.

For the reciprocal, provided neither endpoint equals the pole,

1x+δ−1−1x−1=−δ(x−1)(x+δ−1).\frac1{x+\delta-1}-\frac1{x-1}=\frac{-\delta}{(x-1)(x+\delta-1)}.

The second denominator reveals why a small delta near the pole can have a large effect. If the perturbation touches or crosses x=1, the continuous path contains an undefined input even when both endpoints are finite. The explorer explicitly warns that a local condition estimate cannot describe the whole path.

For stored input x^\widehat x and computed f^\widehat f, the total signed answer error is exactly

f^−f(x)=[f(x^)−f(x)]+[f^−f(x^)].\widehat f-f(x)=\bigl[f(\widehat x)-f(x)\bigr]+\bigl[\widehat f-f(\widehat x)\bigr].

This keeps input representation separate from evaluating the function at that represented input.

Worked example: a million becomes half a million

At x=2 and delta=0.01, exact square values are 4 and 4.0401. The exact output change is 0.0401; the first-order estimate is 0.04, with the remaining 0.0001 supplied by the quadratic term.

At x=1.000001 and delta=0.000001, the reciprocal values are exactly 1000000 and 500000. The input changed by one millionth, yet the answer halved. The local relative condition number at the starting point is 1000001. This finite perturbation equals the starting distance to the pole, so blindly applying a first-order approximation would be inappropriate.

Binary64 cannot store the intended decimal x exactly. The computed reciprocal is compared first with the exact mathematical function at the stored x, then with the intended-decimal answer. The difference between those comparisons is the effect of input representation. The independently checked Fraction reference supplies both intended mathematical values.

Worked example: Perturb the input and track distinct errors

Square: well-conditioned at nonzero x. Relative condition number 2. Representation effect, arithmetic roundoff and total answer error are separate exact rational differences.

Exact mathematical reference
4
Exact perturbed reference
40401/10000
Exact output change
401/10000
Local relative condition number
2
Stored input
2
Computed binary64 answer
4
Effect of input representation
0
Actual evaluation roundoff
0
Total answer error
0

= exact rationals or classifications · ≈ a formatted numerical display. Exceptional values retain their stated meaning.

f(x)=x2,κf(x)=2 (x≠0)f(x)=x^2,\quad\kappa_f(x)=2\ (x\ne0)
E=(f(x^)−f(x))+(f^−f(x^))E=\bigl(f(\widehat x)-f(x)\bigr)+\bigl(\widehat f-f(\widehat x)\bigr)
Exact intended input versus actual stored input.
inputexact referencebinary64 inputbinary64 output
24≈ 2≈ 4
201/10040401/10000≈ 2.00999999999999979≈ 4.04009999999999891

Exact problem

Evaluate the chosen mathematical function on the intended rational input.

Inspect the recorded values\text{Inspect the recorded values}
Actual intermediate values; = exact rationals, ≈ binary64 displays.
quantityvalue
input2
reference4

Select the recorded intermediate values. Previous, next and direct replay navigation preserve immutable numerical history.

Executable reference code

The standard-library reference forms both mathematical answers with Fraction, reads the stored input with Fraction.from_float, and verifies the exact error decomposition. NumPy evaluates an actual array of inputs and contrasts the numerical changes with the exact intended-decimal counterexample. Neither reference uses the browser model to generate its expectation.

code/python/error_conditioning.py
from fractions import Fraction
if __name__ == '__main__':
    x, delta = Fraction('1.000001'), Fraction('0.000001')
    reference = 1/(x-1); changed = 1/(x+delta-1)
    stored = Fraction.from_float(float(x)); at_stored = 1/(stored-1)
    computed = Fraction.from_float(1/(float(x)-1))
    input_effect = at_stored-reference; roundoff = computed-at_stored
    assert reference == 1000000 and changed == 500000
    assert abs(x/(x-1)) == 1000001
    assert input_effect+roundoff == computed-reference
    print('problem condition', abs(x/(x-1)), 'input effect', input_effect, 'roundoff', roundoff)
code/python/error_conditioning_numpy.py
import numpy as np
from fractions import Fraction
if __name__ == '__main__':
    x = np.array([2., 1.000001]); delta = np.array([.01, .000001])
    square_change = np.square(x+delta)-np.square(x)
    reciprocal_change = np.reciprocal(x+delta-1)-np.reciprocal(x-1)
    assert abs(square_change[0]-.0401) < 2e-15
    exact_change = 1/(Fraction('1.000002')-1)-1/(Fraction('1.000001')-1)
    assert exact_change == -500000
    print('square changes', square_change, 'reciprocal changes', reciprocal_change)
    print('Numerical output need not equal the intended exact-decimal problem.')

Explore: keep the question fixed

Begin with the square, change delta and compare the exact change with its linear prediction. Switch to the reciprocal and decrease the distance from x to one. Explain why a fixed input perturbation now matters more.

Select the pole to see undefined real mathematics and a computational infinity together. They are not a valid finite answer. Select cross-pole to see finite endpoint answers alongside the path warning. The warning concerns the mathematical domain, not a plotting limitation.

Use zero in the square example. Its exact value exists, but the relative condition number is undefined because the reference output is zero. Choose an absolute error measure rather than repairing the denominator with an arbitrary epsilon.

Common mistakes and counterexamples

An ill-conditioned problem is not automatically an unstable implementation, and a stable method does not remove intrinsic sensitivity. A tiny observed error for one input does not certify stability for all inputs. Conversely, a large answer error can arise mainly from a sensitive response to unavoidable input conversion.

Rationalizing an expression changes evaluation behavior; it does not change the mathematical function’s conditioning. The next chapter uses that distinction directly. A tolerance is a comparison policy, not a theorem that every error below it is mathematically zero.

Numerical considerations

Inputs are bounded by |x|≤100 and |delta|≤1, with exact decimal parsing. Exact rational references identify poles without a floating epsilon. Computed subtraction and reciprocal are evaluated in actual JavaScript binary64 and their represented outputs are read back exactly before measuring errors.

At x=1 the real reciprocal is undefined. If a nearby intended input rounds to one, the numerical denominator can also become zero, even though the intended mathematical question was finite. The record retains that distinction and does not fabricate a finite error for infinity. No general stability theorem is claimed for these two local demonstrations.

Engineering and ML connections

Sensor uncertainty, finite dataset precision and rounded parameter storage all perturb inputs. A condition estimate helps identify which questions amplify those perturbations. Algorithm design then controls avoidable evaluation errors. In a training diagnostic or linear solve, report the problem, the algorithm and the actual error measure separately so a numerical symptom does not get mistaken for a mathematical guarantee.

Inspect the corresponding representation and error policy before interpreting a computed value.

Exercises

Predict first, then calculate or test the stated claim. Every answer includes corrective feedback and a worked solution.

calculation

A square perturbation

For x=2 and delta=0.01, give the exact change in x².

calculation

Relative square condition

At nonzero x, give |x f′(x)/f(x)| for f(x)=x².

calculation

Sensitive reciprocal

For f(x)=1/(x−1), x=1.000001, delta=0.000001, give the two exact outputs.

explanation

Who owns conditioning?

Which statement separates conditioning from stability?

Choose one answer

explanation

Crossing a pole

A perturbation crosses x=1 for 1/(x−1). What can a local condition number establish?

Choose one answer

Summary and checkpoints

Reproduce both exact perturbation examples. Identify the assumptions behind a relative condition number, detect a pole or a zero-output exception, and split one answer’s error into input effect and roundoff. Explain why problem conditioning and algorithm stability are different properties.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available