Carson Witt
\documentclass[landscape]{article}12% set font encoding for PDFLaTeX or XeLaTeX3\usepackage{ifxetex}4\ifxetex5\usepackage{fontspec}6\else7\usepackage[T1]{fontenc}8\usepackage[utf8]{inputenc}9\usepackage{lmodern}10\fi1112% used in maketitle13\title{Irrational Numbers Project}14\author{Carson Witt}1516\usepackage{amsmath}17\usepackage{lipsum}18\usepackage{enumitem}19\usepackage{listings}20\usepackage{color}2122\definecolor{codegreen}{rgb}{0,0.6,0}23\definecolor{codegray}{rgb}{0.5,0.5,0.5}24\definecolor{codepurple}{rgb}{0.58,0,0.82}25\definecolor{backcolour}{rgb}{0.95,0.95,0.92}2627\lstdefinestyle{mystyle}{28backgroundcolor=\color{white},29commentstyle=\color{codegreen},30keywordstyle=\color{magenta},31numberstyle=\tiny\color{codegray},32stringstyle=\color{codepurple},33basicstyle=\footnotesize,34breakatwhitespace=false,35breaklines=true,36captionpos=b,37keepspaces=true,38numbers=left,39numbersep=5pt,40showspaces=false,41showstringspaces=false,42showtabs=false,43tabsize=244}4546\lstset{style=mystyle}4748% Enable SageTeX to run SageMath code right inside this LaTeX file.49% documentation:50% http://mirrors.ctan.org/macros/latex/contrib/sagetex/sagetexpackage.pdf51% \usepackage{sagetex}525354%% ADDED PREAMBLE55\usepackage{todonotes}56\usepackage[displaymath, mathlines]{lineno}57\usepackage{hyperref}58\usepackage{pagecolor}59\usepackage{tabularx}6061\newcommand{\sg}[1]{\todo[color=red!40,fancyline]{#1}}62\newcommand{\good}[1]{\todo[color=blue!40,fancyline]{#1}}63\newcommand{\comm}[1]{\todo[color=orange!40,fancyline]{#1}}64%%656667\begin{document}6869%% ADDED FEEDBACK70\pagecolor{yellow!30!white}71\mbox{\LARGE Irrationals }\hfill Carson Witt7273\vspace{1cm}7475\hrule7677\vspace{1cm}7879Grade: 1008081\vspace{1cm}8283\begin{tabularx}{15cm}{ |p{6cm} | p{8cm}|}84\hline85Approriate Introduction &86Very nice! I really like the use of subsections within the abstract87to help the reader with your report.88\\89\hline90Proof of the irrationality of $\sqrt{2}$ &91Excellent outline of the proof.92\\93\hline94Explanation of continued fractions &95Very nice! It's great to see you add in the additional detail about96history and background. Stuff like that really adds to the quality of97your report -- and also helps the reader to enjoy reading it!98\\99\hline100Working Python code to approximate one of $e$, $\pi$, or $\sqrt{2}$ &101Yes. Good explanations of the code as well.102\\103\hline104Use of the lstlisting environment &105Yes.106\\107\hline108Proper formatting &109Yes.110\\111\hline112\end{tabularx}113114\newpage115116\listoftodos[List of Comments]117118\newpage119120\maketitle121122\linenumbers123\pagecolor{white}124%%125126127128\section*{Abstract}129130\noindent{\textbf{Introduction:}}131132An irrational number is a number that cannot be expressed as a ratio of two133numbers, or a fraction. Commonly known irrational numbers are the ratio $\pi$ of134a circle's circumference to its diameter, Euler's number $e$, the golden ratio135$\phi$, and the square root of two. All square roots of natural numbers, other136than of perfect squares, are irrational. When expressed as decimals, irrational137numbers do not repeat or terminate. \par138139\noindent{\textbf{History:}}140141According to Wikipedia, "The first proof of the existence of irrational numbers142is usually attributed to a Pythagorean (possibly Hippasus of Metapontum), who143probably discovered them while identifying sides of the pentagram. The then-144current Pythagorean method would have claimed that there must be some145sufficiently small, indivisible unit that could fit evenly into one of these146lengths as well as the other." \par147148\noindent{\textbf{Task For This Project:}}149150In this project, I will be proving that $\sqrt{2}$ is irrational (by151contradiction), explaining continued fractions and showing the continued152fraction for $e$, $\sqrt{2}$, and $\pi$, and writing Python code that153approximates $e$, $\sqrt{2}$, and $\pi$ to a requested number of digits.154155\section*{Context/Work}156157\textbf{Proving that $\sqrt{2}$ is irrational by contradiction:}158159\begin{enumerate}160\item Let's assume that $\sqrt{2}$ is rational, meaning it can be written as the161ratio of two integers, $a$ and $b$:162\end{enumerate}163164$$165\sqrt{2} = \frac{a}{b}166$$167Where $b \neq 0$ and we assume that $a$ and $b$ have no common factors. If168common factors exist, we cancel them in the numerator and denominator.169170\begin{enumerate}[resume]171\item Squaring both sides of the equation gives us:172\end{enumerate}173174$$1752 = \frac{a^2}{b^2}176$$177178\begin{enumerate}[resume]179\item Which implies:180\end{enumerate}181182$$183a^2 = 2b^2184$$185186\begin{enumerate}[resume]187\item This means that $\sqrt{a}$ must be even, since $\sqrt{a}$ is $2$188multiplied by some number. We know this to be true because the multiplication of189two even numbers will always be even.190\item This also means that $a$ itself is even because if $a$ was odd, $a*a$191would be odd as well.192\item Since $a$ is an even number, it is $2$ times another whole number.193\end{enumerate}194195$$196a = 2k197$$198199\begin{enumerate}[resume]200\item If we substitute $a = 2k$ into the squared original equation, we get:201\end{enumerate}202203$$2042 = \frac{(2k)^2}{b^2}205$$206$$2072 = \frac{4k^2}{b^2}208$$209$$2102b^2 = 4k^2211$$212$$213b^2 = 2k^2214$$215216\begin{enumerate}[resume]217\item This means that $b^2$ is even, which follows that $b$ itself is even.218\item \textbf{This is where there is a contradiction.} If $a$ and $b$ are both219even numbers, then $\frac{a}{b}$ is not in its simplest form and still has220common factors. This is a contradiction because we assumed that the equation was221rational and had no common factors from the start. \textbf{Therefore, $\sqrt{2}$222must be irrational.}223\end{enumerate}224225\newpage226227\noindent{\textbf{Continued Fractions:}} \par228229A continued fraction is a fraction of infinite length whose denominator is a230quantity plus a fraction, which latter fraction has a similar denominator, and231so on. Continued fractions are great ways to express irrational numbers like232$e$, $\pi$, and $\sqrt{2}$. \par233234\vspace{0.02cm}{\noindent{Interesting Facts:}}235236\begin{itemize}237\item John Wallis first used the term "continued fraction" in his Arithmetica238Infinitorum of 1653.239\item Another word for a continued fraction is anthyphairetic ratio.240\end{itemize}241242\noindent{The basic form of a continued fraction is as follows:}243244$$245a_0 +\cfrac{b_1}{a_1+\cfrac{b_2}{a_2+\cfrac{b_3}{a_3+\cdots}}}246$$247248where $a_n$ and $b_n$ are either rational numbers, real numbers, or complex249numbers. If $b_n = 1$ for all $n$ the expression is called a simple continued250fraction. If the expression has a finite amount of terms, it is called a finite251continued fraction. Similarly, if the expression has an infinite number of252terms, it is called an infinite continued fraction.253254\vspace{0.02cm}{$e$ as a continued fraction:}255256$$257e = 2+\cfrac{1}{1+\cfrac{1}{2+\cfrac{2}{3+\cfrac{3}{4+\cdots}}}}258$$259260$\pi$ as a continued fraction:261262$$263\pi = {\cfrac{4}{1+\cfrac{1^2}{3+\cfrac{2^2}{5+\cfrac{3^2}{7+\cfrac{4^2}{9+\cdot264s}}}}}}265$$266267$\sqrt{2}$ as a continued fraction:268269$$270\sqrt{2} = 1+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cdots}}}}271$$272273\newpage274275\noindent\textbf{{Python Code For Approximating e:}} \par276277Below is the code I wrote to approximate $e$:278279\begin{lstlisting}[language=Python, caption=Estimator for $e$]280n = input("How many decimals of e would you like to approximate?")281282sum = 0283desired_e = N(e, digits = n + 1)284term_number = 0285286while sum != desired_e:287sum += 1/factorial(term_number)288term_number += 1289290print "NOTE: The code will approximate to the " + str(n) + " digits you291requested, but it will show " + str(n+1) + " digits to prevent rounding errors."292print "-----------------------------------------------------------"293print "Estimated value of e: " + str(N(sum, digits = n + 1))294print "-----------------------------------------------------------"295print "Actual value of e: " + str(desired_e)296print "-----------------------------------------------------------"297print "Difference: " + str((N(desired_e - sum, digits = 2)))298print "-----------------------------------------------------------"299\end{lstlisting}300301\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par302303The code will ask how many digits of $e$ you would like to approximate and store304it in variable $n$. The variable "sum" has an initial value of $0$. While "sum"305is not equal to the actual value of $e$ ("desired{\_}e"), the series expansion306for $e$ (shown below) will be continuously added to "sum", increasing the307"term{\_}number" ($k$) by $1$ integer each time until "sum" does equal308"desired{\_}e". When "sum" does equal "desired{\_}e", the code will exit the309While loop. The code will then print the value of $e$ estimated with the310variable "sum" with $n+1$ digits. Underneath that, the code will print the311actual value of $e$ (stored as a constant by SageMathCloud) with the variable312"desired{\_}e" with $n+1$ digits. The code will then calculate the difference313between the estimated and actual value of $e$ and print that number. NOTE: The314difference should always be zero if the code is properly functioning. \par315316\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $e$:}}} \par317318$$319e =\sum ^{\infty }_{k=0}\dfrac{1}{k!}320$$321322\newpage323324\noindent\textbf{{Python Code For Approximating $\sqrt{2}$:}} \par325326Below is the code I wrote to approximate $\sqrt{2}$:327328\begin{lstlisting}[language=Python, caption=Estimator For $\sqrt{2}$]329n_2 = input("How many decimals of sqrt(2) would you like to approximate?")330331sum_2 = 0332desired_2 = N(sqrt(2), digits = n_2 + 1)333term_number_2 = 0334335while sum_2 != desired_2:336sum_2 += (factorial(2*(term_number_2)+1))/((2^(3*(term_number_2)+1))*(factorial(337term_number_2))^2)338term_number_2 += 1339340print "NOTE: The code will approximate to the " + str(n_2) + " digits you341requested, but it will show " + str(n_2+1) + " digits to prevent rounding342errors."343print "-----------------------------------------------------------"344print "Estimated value of 2: " + str(N(sum_2, digits = n_2 + 1))345print "-----------------------------------------------------------"346print "Actual value of 2: " + str(desired_2)347print "-----------------------------------------------------------"348print "Difference: " + str((N(desired_2 - sum_2, digits = 2)))349print "-----------------------------------------------------------"350\end{lstlisting}351352\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par353354The code for approximating $\sqrt{2}$ is essentially the same as the code for355approximating $e$. The only difference is in the variables and the series356expansions.\par357358\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $\sqrt{2}$:}}} \par359360$$361\sqrt{2} =\sum ^{\infty }_{k=0}\dfrac {\left( 2k+1\right) !}{2^{3k+1}\left(362k!\right) ^{2}}363$$364365\newpage366367\noindent\textbf{{Python Code For Approximating $\pi$}} \par368369Below is the code I wrote to approximate $\pi$:370371\begin{lstlisting}[language=Python, caption=Estimator For $\pi$]372n_pi = input("How many decimals of pi would you like to approximate?")373374sum_pi = 0375desired_pi = N(pi, digits = n_pi + 1)376term_number_pi = 0377378while sum_pi != desired_pi:379sum_pi += (1/(16^term_number_pi))*((4/(8*(term_number_pi)+1))-(2/(8*(term_number380_pi)+4))-(1/(8*(term_number_pi)+5))-(1/(8*(term_number_pi)+6)))381term_number_pi += 1382383print "NOTE: The code will approximate to the " + str(n_pi) + " digits you384requested, but it will show " + str(n_pi+1) + " digits to prevent rounding385errors."386print "-----------------------------------------------------------"387print "Estimated value of pi: " + str(N(sum_pi, digits = n_pi + 1))388print "-----------------------------------------------------------"389print "Actual value of pi: " + str(desired_pi)390print "-----------------------------------------------------------"391print "Difference: " + str((N(desired_pi - sum_pi, digits = 2)))392print "-----------------------------------------------------------"393\end{lstlisting}394395\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par396397The code for approximating $\pi$ is essentially the same as the code for398approximating $e$ and $\sqrt{2}$. The only difference is in the variables and399the series expansions.\par400401\vspace{0.2cm}{\noindent\textbf{{Series Expansion for $\pi$402(Bailey–Borwein–Plouffe Formula):}}} \par403404$$405\pi =\sum ^{\infty }_{k=0}\left[ \dfrac {1}{16^{k}}\left( \dfrac406{4}{8k+1}-\dfrac {2}{8k+4}-\dfrac {1}{8k+5}-\dfrac {1}{8k+6}\right) \right]407$$408409Interestingly enough, the code for approximating $\pi$ gave me the most trouble.410The series expansions that I had previously used in the code either did not411converge fast enough or somehow made the variable "sum{\_}pi" infinitely locked412in the While loop. After some research and trial and error, I discovered the413Bailey–Borwein–Plouffe Formula and decided to try it. It worked perfectly.414415\newpage416417\section*{Conclusion}418419Overall, this has been my favorite project. The code was fairly challenging and420I initially ran into a couple of issues, but this was the first project where I421figured the code out on my own. While I went to Mr. Abell when technical issues422arose, the basic structure of the code was my own. In addition, this is the423first project that I started well in advance of the due date. I usually try to424figure the project out the day it is assigned, but then I put it off until the425last few days. This time, I had finished the code a week or two before the due426date, making it possible for me to write the report without any stress. \par427428I have really enjoyed brushing up my Python skills and learning \LaTeX \space429this year, and I hope I can continue to use these tools in the future, whether430it be for school or just for fun.431432\end{document}433434435