# Taylor Series and Approximation

Computer Science I · Calculus · https://tryals.app/learn/computer-science-i/taylor-series-and-approximation

Computers cannot directly evaluate $\sin x$ or $e^x$; they use **Taylor series** to approximate smooth functions with **polynomials** built from derivatives.

The **Taylor series** of $f$ about point $a$ is:

$$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x - a)^n$$

| Term | What it matches |
| --- | --- |
| **Constant** $f(a)$ | Value at $a$ |
| **Linear** $f'(a)(x-a)$ | Slope at $a$ |
| **Quadratic** | Curvature at $a$ |

Truncating this gives a **Taylor polynomial** that hugs the function near $a$. Setting $a = 0$ yields a **Maclaurin series**, such as $e^x = 1 + x + \frac{x^2}{2!} + \dots$.

## Accuracy and Pitfalls

To compute efficiently, we **replace a hard function by an easy polynomial** matching it locally. The **linear approximation** $f(x) \approx f(a) + f'(a)(x-a)$ is the simplest case and underpins numerical algorithms.

| Feature | Taylor Polynomial |
| --- | --- |
| **Best Region** | Near $a$ |
| **Error Behavior** | Grows as $|x - a|$ increases |

> **Common Pitfall:** Expecting a truncated polynomial to work **far** from $a$. More terms extend the valid region, but finite polynomials remain strictly **local** approximations.

## Practice questions

5 of this lesson's 11 practice questions, with answers. The full set is in the app.

### 1. Complete the statement about where a Taylor polynomial works best.

**Answer:** A truncated Taylor polynomial approximates the function best **near the expansion point**.

**Why:** All the information comes from derivatives at the centre, so the fit is best there and decays with distance. Adding terms widens the good region but never makes a finite polynomial match a function everywhere.

Page: https://tryals.app/practice/computer-science-i/taylor-series-and-approximation/complete-the-statement-about-where-a-taylor-polynomial-works-best

### 2. Select every reason Taylor series matter for computing.

A. The number of terms trades accuracy against cost
B. A polynomial needs only addition and multiplication, which hardware provides
C. They make an approximation exact at every input
D. They remove the need for floating-point arithmetic
E. Functions like sine and the exponential have no finite arithmetic formula

**Answer:** A. The number of terms trades accuracy against cost; B. A polynomial needs only addition and multiplication, which hardware provides; E. Functions like sine and the exponential have no finite arithmetic formula

**Why:** Taylor series exist because hardware can only add and multiply, while sine and the exponential are defined by limits. Choosing how many terms to keep is a genuine engineering decision, but no truncation is exact everywhere and none of it escapes floating-point rounding.

Page: https://tryals.app/practice/computer-science-i/taylor-series-and-approximation/select-every-reason-taylor-series-matter-for-computing

### 3. Libraries compute sin(x) from a polynomial rather than from any geometric definition. Why is a polynomial the right thing for a processor to evaluate?

A. Because polynomial evaluation is the only operation that avoids rounding error.
B. Because the geometric definition of sine cannot be expressed numerically.
C. Because a CPU has only addition and multiplication to work with.
D. Because polynomials are exactly equal to the trigonometric functions they approximate.

**Answer:** C. Because a CPU has only addition and multiplication to work with.

**Why:** A processor adds and multiplies, so evaluating sine means reducing it to operations that exist, and a polynomial is exactly that. The polynomial is *not* equal to sine; it agrees near the expansion point, so implementations first fold the argument into a small range using periodicity. Nor are the coefficients Taylor's: minimax polynomials hit the same accuracy over an interval with fewer terms.

Page: https://tryals.app/practice/computer-science-i/taylor-series-and-approximation/libraries-compute-sin-x-from-a-polynomial-rather-than-from-any

### 4. Order what the successive Taylor terms make the polynomial match, starting from the centre.

**Answer:**

1. The value of the function at the centre
2. The slope of the function at the centre
3. The curvature of the function at the centre
4. The rate at which the curvature itself changes

**Why:** Value, slope, curvature, then the change in curvature, one extra derivative matched per term. Truncating the series therefore means giving up on matching the higher derivatives, which is why the fit decays as you move away from the centre.

Page: https://tryals.app/practice/computer-science-i/taylor-series-and-approximation/order-what-the-successive-taylor-terms-make-the-polynomial-match

### 5. A NumPy operation on a million-element array runs fifty times faster than the equivalent Python loop, performing identical arithmetic. Where does the time go in the loop?

A. Into a superior algorithm used internally by the library
B. Into interpreter overhead per element: dispatch, type checks, boxing
C. Into automatic GPU offloading that the loop does not trigger
D. Into performing fewer total arithmetic operations

**Answer:** B. Into interpreter overhead per element: dispatch, type checks, boxing

**Why:** A million interpreter round-trips against one, plus contiguous memory and SIMD in the compiled loop. None of the speedup comes from doing less arithmetic, which is why 'vectorise it' is the first optimisation in scientific Python and means nothing in C.

Page: https://tryals.app/practice/computer-science-i/taylor-series-and-approximation/a-numpy-operation-on-a-million-element-array-runs-fifty-times-faster
