---
title: Problem set 1
heading: "Problem set 1: floating point, error and simple iterations"
eyebrow: A13 · Problem set 1
type: problems
---

::: hook
These problems use lessons 1 to 4: floating-point formats and spacing, rounding and cancellation, conditioning and stability, bisection and fixed-point iteration. Double precision has 53 significant bits.
:::

::: pool
pick: 12

::: check
kind: parts
given: x = 100 | 5000 | 0.2

## Doubles near x = {x}.

::: part
answer: 2^(floor(ln(x)/ln(2)) - 52)
tolerance: 0.5%

### What's the spacing between neighbors there?

::: misses
- [any] $2^{\lfloor\log_2 x\rfloor - 52}$.
:::
:::

::: part
answer: 2^(floor(ln(x)/ln(2)) - 52)/x
tolerance: 0.5%

### What's that spacing relative to x?

::: misses
- [any] Divide by x.
:::
:::
:::

::: check
kind: parts
given: p = 8 | 11 | 16 | 24 | 53 | 64

## A format has {p} significant bits.

::: part
answer: 2^(1 - p)
tolerance: 0.5%

### What's its machine epsilon?

::: misses
- [any] $2^{1-p}$.
:::
:::

::: part
answer: 2^p
tolerance: 0.01%

### Above what integer does it first skip integers?

::: misses
- [any] $2^p$.
:::
:::
:::

::: check
kind: parts
given: s = 0.001 | 0.01 | 0.03 | 0.1 | 0.3 | 1

## A float32 running total adds {s} each step.

::: part
answer: 2^(floor(23 + ln(2*s)/ln(2)) + 1)
tolerance: 0.5%

### From what total does an addition stop changing it?

::: misses
- [any] The first $2^k$ with $2^{k - 24} > s$.
:::
:::

::: part
answer: 2^(floor(52 + ln(2*s)/ln(2)) + 1)
tolerance: 0.5%

### And for a double running total?

::: misses
- [any] The first $2^k$ with $2^{k - 53} > s$.
:::
:::
:::

::: check
kind: parts
given: d = 0.01 | 0.001 | 0.0001 | 0.00001 | 0.000001 | 0.0000001

## Subtracting b = 1 from a = 1 + {d}.

::: part
answer: (2 + d)/d
tolerance: 1%

### By about what factor does the relative error grow?

::: misses
- [any] $(a + b)/(a - b)$.
:::
:::

::: part
answer: log((2 + d)/d)
tolerance: 1%

### About how many decimal digits does that cost?

::: misses
- [any] $\log_{10}$ of the factor.
:::
:::
:::

::: check
kind: parts
given: b = 1000000 | 30000000; c = 2 | 9

## $x^2 - \given{b}x + \given{c} = 0$.

::: part
answer: 2*c/(b + sqrt(b^2 - 4*c))
tolerance: 0.5%

### What's the small root?

::: misses
- [any] $\frac{2c}{b + \sqrt{b^2 - 4c}}$.
:::
:::

::: part
answer: (b + sqrt(b^2 - 4*c))/2
tolerance: 0.5%

### What's the large root?

::: misses
- [any] $\frac{b + \sqrt{b^2 - 4c}}{2}$: no cancellation here.
:::
:::
:::

::: check
kind: parts
given: d = 0.0001 | 0.01; y = 10 | 40

## Condition numbers.

::: part
answer: 1/abs(ln(1 + d))
tolerance: 0.5%

### What's κ for $\ln x$ at x = 1 + {d}?

::: misses
- [any] $1/\lvert\ln x\rvert$.
:::
:::

::: part
answer: y
tolerance: 0.5%

### What's κ for $e^x$ at x = {y}?

::: misses
- [any] $\lvert x\rvert$.
:::
:::
:::

::: check
kind: parts
given: k = 4 | 9; x = 15 | 25

## Stability and conditioning.

::: part
answer: 15.95 - k
tolerance: 1%

### A system has $\kappa = 10^{\given{k}}$. About how many digits can a stable solver deliver?

::: misses
- [any] $15.95 - \log_{10}\kappa$.
:::
:::

::: part
answer: x^x/x!
tolerance: 1%

### The series for $e^{-\given{x}}$ has terms up to what size?

::: misses
- [any] $x^x/x!$, at k = x.
:::
:::
:::

::: check
kind: parts
given: W = 1 | 8; d = 0.0001 | 0.00000001

## Bisection on a bracket {W} wide.

::: part
answer: ceil(ln(W/d)/ln(2) - 1)
tolerance: 0

### How many steps guarantee an error below {d}?

::: misses
- [any] Smallest n with $W/2^{n+1} \le \delta$.
:::
:::

::: part
answer: W/2^21
tolerance: 0.5%

### What's the guaranteed error after 20 steps?

::: misses
- [any] $W/2^{n+1}$.
:::
:::
:::

::: check
kind: parts
given: c = 1..10 int

## The iteration $x \leftarrow \given{c} + 1/x$.

::: part
answer: (c + sqrt(c^2 + 4))/2
tolerance: 0.5%

### What does it converge to?

::: misses
- [any] The positive root of $x^2 - cx - 1$.
:::
:::

::: part
answer: 1/((c + sqrt(c^2 + 4))/2)^2
tolerance: 0.5%

### By what factor does each step shrink the error?

::: misses
- [any] $\lvert g'(x^*)\rvert = 1/x^{*2}$.
:::
:::
:::

::: check
kind: parts
given: r = 0.2 | 0.8; d = 9 | 15

## A linear iteration with rate {r}.

::: part
answer: d/log(1/r)
tolerance: 1%

### About how many steps for {d} digits?

::: misses
- [any] $d/\log_{10}(1/\rho)$.
:::
:::

::: part
answer: r/(1 - r)
tolerance: 0.5%

### If the last step changed x by 1 unit, about how far is x from the answer, in those units?

::: misses
- [any] $\frac{\rho}{1 - \rho}$ times the last step.
:::
:::
:::

::: check
kind: parts
given: V = 5 | 9; R = 1000 | 2200

## A {V} V source drives a diode ($I_s = 10^{-14}$ A, $nV_T$ = 25.85 mV) through {R} Ω.

::: part
answer: 0.02585*ln((V - 0.7)/R/1e-14 + 1)
unit: V
tolerance: 0.1%

### What's $V_D$ after one step from 0.7 V of $V_D \leftarrow nV_T\ln\left(\frac{(V - V_D)/R}{I_s} + 1\right)$?

::: misses
- [any] Current from the guess, then the voltage.
:::
:::

::: part
answer: 0.02585/(V - 0.7)
tolerance: 1%

### What's $\lvert g'\rvert$ near there, $\frac{nV_T}{V - V_D}$, with $V_D$ ≈ 0.7 V?

::: misses
- [any] $nV_T/(V - V_D)$.
:::
:::
:::

::: check
kind: parts
given: x = 100000000 | 200000000 | 500000000 | 1000000000 | 3000000000 | 10000000000

## $\sqrt{x^2 + 1} - x$ at x = {x}.

::: part
answer: 1/(sqrt(x^2 + 1) + x)
tolerance: 0.5%

### What's its true value?

::: misses
- [any] $\frac{1}{\sqrt{x^2 + 1} + x}$.
:::
:::

::: part
answer: 0
tolerance: 0.000000000001

### What does double precision give when it's computed as written?

::: misses
- [any] $x^2 + 1$ rounds to $x^2$.
:::
:::
:::

::: check
kind: parts
given: p = 11 | 24 | 53

## A binary format has {p} significant bits.

::: part
answer: 2^(-p)
tolerance: 0.5%

### What is its unit roundoff?

::: misses
- [2^(1 - p)] That's machine epsilon; rounding to nearest errs by at most half of it.
- [any] $2^{-p}$.
:::
:::

::: part
answer: p*log(2)
tolerance: 0.5%

### About how many decimal digits does it carry?

::: misses
- [any] $p\log_{10}2$.
:::
:::
:::

::: check
kind: parts
given: d = 0.001 | 0.00001 | 0.0000001

## Two positive numbers of similar size, each with a tiny relative error, differ by a relative amount {d}. They are subtracted.

::: part
answer: 2/d
tolerance: 1%

### By about what factor does the subtraction amplify their relative errors?

::: misses
- [1/d] Both inputs' errors count: $\frac{\lvert a\rvert + \lvert b\rvert}{\lvert a - b\rvert} \approx \frac2d$.
- [any] $\frac{\lvert a\rvert + \lvert b\rvert}{\lvert a - b\rvert}$.
:::
:::
:::

::: check
kind: parts
given: W = 1 | 4; t = 0.000001 | 0.000000001

## Bisection starts on a bracket {W} wide.

::: part
answer: ceil(log(W/t)/log(2))
tolerance: 0

### How many steps shrink the bracket below {t}?

::: misses
- [any] After n steps the bracket is $W/2^n$.
:::
:::
:::
:::
