\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amstext}
\usepackage{array}

\title{Howework 2 -- Introduction to Computational Science}
\author{Claudio Maggioni}

\begin{document}
\maketitle
\section*{Question 1}
The solutions assume that the sign bit $1$ is negative and $0$ is positive.

\subsection*{Point a}
\begin{itemize}
\item 13 is equal to $0 1010 0000 000 1011$;
\item 42.125 is equal to $0 0101 0001 000 1101$;
\item 0.8 is equal to $0 1 1001 1001 100 0011$. 0.78 is approximated to 0.7998046875;
\end{itemize}

\subsection*{Point b}
$1 0110 1011 100 1101$ is $(-1) * (0.25+0.125+0.03125+0.0078125+0.00320625+0.001953125) *2^5$,
which is equal to $-13.4151$.

\subsection*{Point c}
$x_{max}$ is $0 1111 1111 111 1111$, equal to $255.9375$. Since denormalized numbers do not
belong to this representation (since the exponent $0000$ cannot be used for valid numbers other
than 0) $x_{min}$ is $0 0000 0000 000 0001$, equal to $0.0078125$.

\section*{Question 2}
\subsection*{Point a}
$$\frac{(x + \Delta x) + (y + \Delta y) - (x + y)}{x + y} = \frac{\Delta x}{x + y} + \frac{\Delta y}{x + y} = \frac{x}{x + y}\frac{\Delta x}{x} +
\frac{y}{x + y}\frac{\Delta y}{y}$$

\subsection*{Point b}
$$\frac{(x + \Delta x) - (y + \Delta y) - (x - y)}{x - y} = \frac{\Delta x}{x - y} - \frac{\Delta y}{x - y} = \frac{x}{x - y}\frac{\Delta x}{x} -
\frac{y}{x - y}\frac{\Delta y}{y}$$

\subsection*{Point c}
$$\frac{((x + \Delta x) (y + \Delta y)) - (x y)}{x y} = \frac{y \Delta x + x \Delta y + \Delta x \Delta y}{x y} \approx
\frac{y \Delta x + x \Delta y}{x y} = \frac{\Delta x}{y} + \frac{\Delta y}{x}$$

\subsection*{Point d}
$$\frac{((x + \Delta x) / (y + \Delta y)) - (x / y)}{x / y}
= \frac{\frac{(x + \Delta x) y}{(y + \Delta y) y} - \frac{(y + \Delta y)x}{(y + \Delta y)y}}{x / y}
= \frac{y \Delta x  - x \Delta y}{x (y + \Delta y)}
= \frac{y \Delta x}{x(y + \Delta y)} - \frac{\Delta y}{y + \Delta y} = $$
$$ = \left(\frac{x(y + \Delta y)}{y \Delta x}\right)^{-1} - \left(\frac{y + \Delta y}{\Delta y}\right)^{-1}
= \left(\frac{x}{\Delta x} - \frac{y \Delta x}{x \Delta y}\right)^{-1} - \left(\frac{y}{\Delta y} + 1\right)^{-1} = $$
$$ = \left(\frac{x}{\Delta x} \left(1 - \frac{\Delta y}{y}\right)\right)^{-1} - \left(\frac{y}{\Delta y} + 1\right)^{-1}
\approx \left(\frac{x}{\Delta x}\right)^{-1} - \left(\frac{y}{\Delta y}\right)^{-1}
= \frac{\Delta x}{x} - \frac{\Delta y}{y}
$$

\subsection*{Point e}
Division and multiplication may suffer from cancellation.

\section*{Exercise 3}
\subsection*{Point d}
The error at first keeps getting exponentially smaller due to a better approximation of $h$ when computing the derivative
(i.e. $h$ is exponentially nearer to 0), but at $10^{-9}$ this trend almost becomes the opposite due to loss of significant
digits when subtracting from $e^{x+h}$ $e^x$ and amplifiying this error by effectively multiplying that with exponentially
increasing powers of 10.
\end{document}
