$\newcommand{\eps}{\varepsilon} \newcommand{\kron}{\otimes} \DeclareMathOperator{\diag}{diag} \DeclareMathOperator{\trace}{trace} \DeclareMathOperator{\rank}{rank} \DeclareMathOperator*{\minimize}{minimize} \DeclareMathOperator*{\maximize}{maximize} \DeclareMathOperator{\subjectto}{subject to} \newcommand{\mat}[1]{\boldsymbol{#1}} \renewcommand{\vec}[1]{\boldsymbol{\mathrm{#1}}} \newcommand{\vecalt}[1]{\boldsymbol{#1}} \newcommand{\conj}[1]{\overline{#1}} \newcommand{\normof}[1]{\|#1\|} \newcommand{\onormof}[2]{\|#1\|_{#2}} \newcommand{\MIN}[2]{\begin{array}{ll} \minimize_{#1} & {#2} \end{array}} \newcommand{\MINone}[3]{\begin{array}{ll} \minimize_{#1} & {#2} \\ \subjectto & {#3} \end{array}} \newcommand{\MINthree}[5]{\begin{array}{ll} \minimize_{#1} & {#2} \\ \subjectto & {#3} \\ & {#4} \\ & {#5} \end{array}} \newcommand{\MAX}[2]{\begin{array}{ll} \maximize_{#1} & {#2} \end{array}} \newcommand{\MAXone}[3]{\begin{array}{ll} \maximize_{#1} & {#2} \\ \subjectto & {#3} \end{array}} \newcommand{\itr}[2]{#1^{(#2)}} \newcommand{\itn}[1]{^{(#1)}} \newcommand{\prob}{\mathbb{P}} \newcommand{\probof}[1]{\prob\left\{ #1 \right\}} \newcommand{\pmat}[1]{\begin{pmatrix} #1 \end{pmatrix}} \newcommand{\bmat}[1]{\begin{bmatrix} #1 \end{bmatrix}} \newcommand{\spmat}[1]{\left(\begin{smallmatrix} #1 \end{smallmatrix}\right)} \newcommand{\sbmat}[1]{\left[\begin{smallmatrix} #1 \end{smallmatrix}\right]} \newcommand{\RR}{\mathbb{R}} \newcommand{\CC}{\mathbb{C}} \newcommand{\eye}{\mat{I}} \newcommand{\mA}{\mat{A}} \newcommand{\mB}{\mat{B}} \newcommand{\mC}{\mat{C}} \newcommand{\mD}{\mat{D}} \newcommand{\mE}{\mat{E}} \newcommand{\mF}{\mat{F}} \newcommand{\mG}{\mat{G}} \newcommand{\mH}{\mat{H}} \newcommand{\mI}{\mat{I}} \newcommand{\mJ}{\mat{J}} \newcommand{\mK}{\mat{K}} \newcommand{\mL}{\mat{L}} \newcommand{\mM}{\mat{M}} \newcommand{\mN}{\mat{N}} \newcommand{\mO}{\mat{O}} \newcommand{\mP}{\mat{P}} \newcommand{\mQ}{\mat{Q}} \newcommand{\mR}{\mat{R}} \newcommand{\mS}{\mat{S}} \newcommand{\mT}{\mat{T}} \newcommand{\mU}{\mat{U}} \newcommand{\mV}{\mat{V}} \newcommand{\mW}{\mat{W}} \newcommand{\mX}{\mat{X}} \newcommand{\mY}{\mat{Y}} \newcommand{\mZ}{\mat{Z}} \newcommand{\mLambda}{\mat{\Lambda}} \newcommand{\mPbar}{\bar{\mP}} \newcommand{\ones}{\vec{e}} \newcommand{\va}{\vec{a}} \newcommand{\vb}{\vec{b}} \newcommand{\vc}{\vec{c}} \newcommand{\vd}{\vec{d}} \newcommand{\ve}{\vec{e}} \newcommand{\vf}{\vec{f}} \newcommand{\vg}{\vec{g}} \newcommand{\vh}{\vec{h}} \newcommand{\vi}{\vec{i}} \newcommand{\vj}{\vec{j}} \newcommand{\vk}{\vec{k}} \newcommand{\vl}{\vec{l}} \newcommand{\vm}{\vec{l}} \newcommand{\vn}{\vec{n}} \newcommand{\vo}{\vec{o}} \newcommand{\vp}{\vec{p}} \newcommand{\vq}{\vec{q}} \newcommand{\vr}{\vec{r}} \newcommand{\vs}{\vec{s}} \newcommand{\vt}{\vec{t}} \newcommand{\vu}{\vec{u}} \newcommand{\vv}{\vec{v}} \newcommand{\vw}{\vec{w}} \newcommand{\vx}{\vec{x}} \newcommand{\vy}{\vec{y}} \newcommand{\vz}{\vec{z}} \newcommand{\vpi}{\vecalt{\pi}} \newcommand{\vlambda}{\vecalt{\lambda}}$

# Homework 1

Please answer the following questions in complete sentences in a typed manuscript and submit the solution on blackboard by on February 1st at noon.

## Problem 0: Homework checklist

• Please identify anyone, whether or not they are in the class, with whom you discussed your homework. This problem is worth 1 point, but on a multiplicative scale.

• Make sure you have included your source-code and prepared your solution according to the most recent Piazza note on homework submissions.

## Problem 1: Gautschi Exercise 1.1

1. Enumerate all positive elements of $\RR(3,2)$ that correspond to normalized floating point values. (Recall that $\RR(3,2)$ is a floating point system that uses 2-bits for the exponent and 3-bits for the significand or mantissa.) List each number on one line as a decimal.

2. What is the distance $d(x)$ of a positive normalized floating point number to its next larger floating-point number? (Do this for all values in $RR^(3,2)$.)

3. Determine the relative distance $r(x) = d(x)/x$ for all numbers and give upper and lower bounds.

## Problem 2: Gautschi Exercise 1.11

Let $f(x) = \sqrt{1 + x^2} - 1$.

1. Explain the difficulty of computing $f(x)$ for a small value of $|x|$ and show how it can be circumvented.

2. Determine an expression for the condition number of $f(x)$ and discuss conditioning for small $|x|$.

3. How can the answers to 1 and 2 be reconciled?

## Problem 3: Gautschi Machine Exercise 1.4

Euler's constant $\gamma = 0.57721566490153286\ldots$ is defined as the limit Assuming that $\gamma - \gamma_n \sim c n^{-d}$, try to determine $c$ and $d$ on the computer.

## Problem 4: Gautschi Machine Exercise 1.6a.

Write a program to compute once using the first formula and once using the second formula. For $N = 10^k, k = 1, 2, \ldots, 7$, print the respective absolute errors. Comment on the results.

## Problem 5: The Hurwitz zeta function

This is a real problem that I ran into! I was using a program written by someone else to compute a particular statistical estimate. The details don't really matter, but at one step, the code needed to compute the Hurwitz zeta function: where $s$ ranged from 1 to 7 and where $q$ ranged from 1 to 500. They were using Matlab, which doesn't provide a function for the Hurtwitz zeta function, but does provide a function for the Riemann zeta function: Note that the only difference between these two functions is that the first term in the Riemann zeta function is $1/(1^s)$ and the first term in the Hurwitz zeta function is $1/(q^s)$. To account for this difference, the code I was using did the following:

 function h=hzeta(s,q)
z = zeta(s)
h = z - sum((1:(q-1)).^(-s));


Was I happy when I realized this? You should use what you've learned about floating point computations to answer this question. You can evaluate the Hurwitz zeta function to arbitrary precision via Wolfram Alpha.

## Problem 6

Suppose you want to evaluate $a + b + c$ on a machine. Suppose that $a > b > c > 0$ and that $a,b,c$ are all exact on the machine. Empirically illustrate that Now prove which of the three orders of evaluation result in the smallest error. (The three are (a+b)+c, (a+c)+b, a+(b+c).)

## Problem 7

The Intel Penitum FDIV bug was illustrated with the procedure: Determine the accuracy of this computation assuming that $A$ and $B$ can be exactly stored in floating point on the computer.

## Problem 8

1. We want to understand computer implementations of methods to compute the roots of the quadratic equation given the coefficients $a,b,c$ in using the high school formula Show empirically that this formula can result in catastrophic errors in the computed roots and identify the cause.

2. Consider Gautschi's suggestion in problem 9. Suppose we take (without loss of generality) the quadratic with roots $x_1, x_2$. Suppose we compute the larger root first, and then use $x_1 x_2 = q$ to determine the additional root. This results in the Julia program:

x1=abs(p/2) + sqrt(p*p/4 - q)
if p > 0
x1 = -x1
end
x2 = q/x1


Find two serious flaws with this program as a "general-purpose" quadratic equation solver. Support your arguments with specific examples, if necessary.

3. Consider reading Kahan's note on quadratics for more on how to accurately evaluate them. https://www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf