This is worth 5 points extra credit if done properly and turned in by May 18.
Get this as an ipynb file for IJulia.
Newton-Raphson Division is a means to divide by multiplying. Why would you want to do that? Well, even for computers division is harder (read slower) than multiplying.The trick is that $p/q$ is simply $p \cdot (1/q)$, so finding a means to compute a reciprocal by multiplying will reduce division to multiplication. (This trick is used by yeppp, a high performance library for computational mathematics.)
Well suppose we have $q$, we could try to use Newton's method to find $1/q$, as it is a solution to $f(x) = x - 1/q$. The Newton update step $x - f(x) / f'(x)$ simplifies to:
$$~ x - (x - 1/q)/ 1 = 1/q. ~$$That doesn't really help, as Newton's method is just $x_{i+1} = 1/q$ – that is it just jumps to the answer, the one we want to compute by some other means. That isn't so helpful.
Let's try again, simplify the update step for a related function: $f(x) = 1/x - q$ and then write the julia
code for one step of Newton's method (your answer should look something like $x = 1/2 \cdot (x + q/x)$, though that solves $\sqrt{q}$):
Now for $q$ in the interval $[1/2, 1]$ we want to get a good initial guess. Here is a claim. We can use $x_0=48/17 - 32/17 q$. Let's check:
Make a graph of both $y=1/x$ and $y=48/17 - 32/17 \cdot x$ on this interval. If you look closely you should see that the largest difference between the two graphs is at the endpoints and the midpoint.
Graphically estimate the largest difference:
Here is something that people have shown to be true: for any $q$ in $[1/2, 1]$ and with the initial guess $x_0 = 48/17 - 32/17q$, Newton's method will converge to 16 digits of accuracy in no more than this many steps:
$$~ \log_2(\frac{53 + 1}{\log_2(17)}). ~$$What is the smallest integer as large as this value?
For $q = 0.80$, find $1/q$ using the above. Write your commands showing all the steps you needed.
Finally, any thoughts on what to do to find $p/q$ this way if $q$ is not in the interval $[1/2, 1]$?