# Chapter 20 notebook: Numerical Methods: Approximation You Can Trust

**Goal:** Budget a numerical computation and verify its accuracy with an independent check.

**Start with:** Rules 20.3.4, 20.3.5, 20.3.7. Use a calculator or the optional Python lab. Programming is optional for the workbook; the Jupyter version requires a Python 3 kernel. All lab numbers are constructed practice inputs, not observed data.

**Source:** [Finished Chapter 20](../skills/math-thumb-numerical-methods/references/chapter.md) from *Mathematical Rules of Thumb*. Numbered rules, classifications, and the decision path come from the book. The lab, exercises, answer key, and worksheet prompts are companion additions.

## 1. Frame your decision

Write a question in which an answer would change something you do. Gather: Function or data; domain; root bracket or integration interval; smoothness; conditioning; precision and tolerance; coupled error sources.

- My question and intended decision:
- Known inputs and units:
- Required accuracy or threshold:
- What I expect before calculating:
- What I still need to find out:

Use the lab as a worked starting point if you do not yet have your own problem. For notation or prerequisites, ask the chapter skill to explain only the concept blocking the next step.

## 2. Choose a route

- **Does a small residual support the claimed answer?** Normalize it, estimate conditioning, and check the quantity of interest before inferring forward accuracy.
- **Is the algorithm itself stable?** Compute a backward error in a structure and scale that represent scientifically acceptable input perturbations.
- **Is arithmetic representation losing information?** Use compensated reduction, Horner nesting, or barycentric interpolation before increasing precision.
- **Is a numerical derivative needed?** Scale the input, choose forward or centered differences from domain access, sweep nearby steps, and use complex-step only through analytic code.
- **Are interpolation samples selectable?** Use Chebyshev-like nodes for a global polynomial; otherwise prefer a representation suited to fixed, noisy, or nonsmooth data.
- **Is an integral smooth and freely sampled?** Use an appropriate Gaussian family; split at known nonsmooth locations and audit adaptive error estimates.
- **Is a convergence order advertised?** Run at least three resolutions with controlled coupled errors and estimate the observed rate before extrapolating.
- **Is a scalar root bracketed?** Budget bisection first, then permit secant or Newton acceleration without surrendering containment.
- **Can a root solver stop safely?** Require a meaningful residual plus location, correction, or bracket evidence, with condition checks near singular roots.

**Chapter-specific stop check:** Convergence order, residual size, and solver success flags require interpretation. Establish continuity before treating a sign change as a root bracket.

## 3. Work the lab

Find sqrt(2) as the root of x^2-2 on [1,2]. Require a final bracket width at most 1e-6. Bisection needs ceil(log2(1/1e-6))=20 interval halvings. The midpoint of the final bracket is then within 0.5e-6 of the root. This location certificate follows from continuity and a preserved sign-changing bracket, not from a small residual alone.

Predict the sign and scale before running the code. Then change one input and explain why the result moves. The code checks the constructed example; it does not prove the rule for every possible input. Code assertions may describe the example's chosen regime, so inspect them before changing that regime.

```python
import math
left, right, width_tolerance = 1.0, 2.0, 1e-6
def f(x):
    return x*x-2
assert f(left)*f(right) < 0 and width_tolerance > 0
budget = max(0, math.ceil(math.log2((right-left)/width_tolerance)))
for iteration in range(budget):
    midpoint = (left+right)/2
    if f(left)*f(midpoint) <= 0:
        right = midpoint
    else:
        left = midpoint
answer = (left+right)/2
print(f"Halvings: {budget}; final width: {right-left:.9g}; answer: {answer:.9f}")
print(f"Certified midpoint error <= {(right-left)/2:.9g}")
assert left <= math.sqrt(2) <= right and right-left <= width_tolerance
```

**My prediction, observed result, and explanation:**

_Record your work here._

## 4. Practise without the answers

### Exercise 1

Errors on grids h, h/2, h/4 are 0.04, 0.01, 0.0025. What observed order do they suggest?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

### Exercise 2

A root solver reports |f(x)|=1e-8 with local |f'(x)|≈1e-6. What is the local correction scale?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

### Exercise 3

Can a sign change across x=0 certify a zero of f(x)=1/x on [-1,1]?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

**Coaching prompt:** “Use the Chapter 20 skill to help me with Exercise 2. Ask for my attempt, give one useful hint if I need it, and help me check the assumptions before showing the answer.”

## 5. Answer key and reasoning

Read this after attempting the exercises, or use it immediately if you prefer a complete walkthrough. An answer is complete only when its assumptions and stopping point are clear.

### Answer 1

Each halving reduces error by four, giving log2(4)=2. This supports second order in the tested regime, assuming other errors are controlled.

### Answer 2

|f/f'|≈0.01. A small residual may correspond to a substantial location error near a flat root; inspect a bracket or other location evidence.

### Answer 3

No. Continuity fails at zero, so the intermediate-value argument behind the bracket is invalid. Split the domain at singularities.

## 6. Build the complete chapter toolkit

The new lab samples the chapter; the following checklist covers all 19 rules. Study one thematic group at a time. A large group can take several sessions.

- **Separate Problem Difficulty From Algorithm Failure:** work with rules 20.1.1, 20.1.2, 20.1.3, 20.1.4, 20.1.5.
- **Choose Nodes and Steps That Balance Error:** work with rules 20.2.1, 20.2.2, 20.2.3, 20.2.4, 20.2.5, 20.2.6.
- **Budget Iterations and Verify Convergence:** work with rules 20.3.1, 20.3.2, 20.3.3, 20.3.4, 20.3.5, 20.3.6, 20.3.7, 20.3.8.

For each selected rule, read its equation, explanation, and worked use in the source. Reproduce that example; change one input; then change one assumption so the rule is no longer justified. Record the result and what check catches the failure. Historical examples remain labeled and qualified as in the source.

Read each complete numbered profile in the [chapter reference](../skills/math-thumb-numerical-methods/references/chapter.md) before applying it. The cues below abbreviate the graph metadata; they are not complete conditions. Change the status only after doing the practice described below.

| Rule | Book role | First assumptions to inspect | Practice status |
|---|---|---|---|
| 20.1.1: Interpret a residual through conditioning | Workflow | compatible condition measure;  scale aware residual | new |
| 20.1.2: Use backward error to distinguish stability from conditioning | Workflow | meaningful nearby problem;  compatible condition measure | new |
| 20.1.3: Use compensated summation for long mixed-scale sums | Workflow | floating point model;  finite nonoverflowing terms | new |
| 20.1.4: Use Horner's rule for polynomial evaluation | Workflow | floating point model;  well scaled inputs | new |
| 20.1.5: Evaluate interpolating polynomials in barycentric form | Workflow | floating point model;  well scaled inputs | new |
| 20.2.1: Use a square-root-epsilon step for forward differences | Workflow | floating point model;  well scaled inputs | new |
| 20.2.2: Use a cube-root-epsilon step for centered differences | Workflow | floating point model;  well scaled inputs | new |
| 20.2.3: Use complex-step differentiation when the code is analytic | Workflow | floating point model;  well scaled inputs | new |
| 20.2.4: Use Chebyshev-like nodes for high-degree global interpolation | Workflow | floating point model;  well scaled inputs | new |
| 20.2.5: An n-point Gauss rule integrates degree 2n-1 polynomials exactly | Independent | floating point model;  well scaled inputs | new |
| 20.2.6: Split adaptive quadrature where the integrand is difficult | Specialized | floating point model;  well scaled inputs | new |
| 20.3.1: Expect a factor of four from halving trapezoid spacing | Workflow | floating point model;  well scaled inputs | new |
| 20.3.2: Expect a factor of sixteen from halving Simpson spacing | Workflow | floating point model;  well scaled inputs | new |
| 20.3.3: Use step halving to extrapolate away leading error | Workflow | floating point model;  well scaled inputs | new |
| 20.3.4: Verify a claimed discretization order on three resolutions | Workflow | floating point model;  well scaled inputs | new |
| 20.3.5: Budget bisection iterations from the bracket width | Independent | floating point model;  well scaled inputs | new |
| 20.3.6: Expect secant convergence of order about 1.62 | Independent | floating point model;  well scaled inputs | new |
| 20.3.7: Safeguard Newton with a bracket | Specialized | floating point model;  well scaled inputs | new |
| 20.3.8: Stop Newton using the correction as well as the residual | Workflow | reliable newton correction;  scale aware residual | new |

For a completed row, record: **rule number / my new input / mathematical claim type / verified assumptions / calculation / check / valid use / rejected use / next step**. “Practised” means you worked an example. “Demonstrated” means you can explain a valid use, transfer it, and reject a misuse without the answer key.

## 7. Apply it to your own problem

Return to your opening question. Choose the smallest rule set that can settle it. Use the book's independent/workflow/specialized classification separately from the claim type (exact, approximate, bound, diagnostic, or heuristic).

- Selected rule number(s) and reason:
- Assumptions that hold, fail, or remain uncertain:
- Substitution with units:
- Result and error, uncertainty, or bound:
- Independent check or limiting case:
- Decision this supports:
- Stop here, do a named next calculation, or gather missing information:

## 8. Transfer and continue

Useful nearby chapters: Chapter 5: analysis; Chapter 7: linear algebra; Chapter 21: scientific computing. Bring the question, units, assumptions, result type, and uncertainty to the next chapter. Choose a bridge only when it supplies an operation you actually need.

**Completion check:** Explain this chapter's lab in your own words; solve one changed-input exercise; reject one invalid use; and produce a decision record for your own problem. If one check fails, revisit that part of the chapter rather than marking every rule complete.
