Carson Witt
\documentclass{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: http://mirrors.ctan.org/macros/latex/contrib/sagetex/sagetexpackage.pdf50% \usepackage{sagetex}5152\begin{document}53\maketitle5455\section*{Abstract}5657\noindent{\textbf{Introduction:}}5859An irrational number is a number that cannot be expressed as a ratio of two numbers, or a fraction. Commonly known irrational numbers are the ratio $\pi$ of a circle's circumference to its diameter, Euler's number $e$, the golden ratio $\phi$, and the square root of two. All square roots of natural numbers, other than of perfect squares, are irrational. When expressed as decimals, irrational numbers do not repeat or terminate. \par6061\noindent{\textbf{History:}}6263According to Wikipedia, "The first proof of the existence of irrational numbers is usually attributed to a Pythagorean (possibly Hippasus of Metapontum), who probably discovered them while identifying sides of the pentagram. The then-current Pythagorean method would have claimed that there must be some sufficiently small, indivisible unit that could fit evenly into one of these lengths as well as the other." \par6465\noindent{\textbf{Task For This Project:}}6667In this project, I will be proving that $\sqrt{2}$ is irrational (by contradiction), explaining continued fractions and showing the continued fraction for $e$, $\sqrt{2}$, and $\pi$, and writing Python code that approximates $e$, $\sqrt{2}$, and $\pi$ to a requested number of digits.6869\section*{Context/Work}7071\textbf{Proving that $\sqrt{2}$ is irrational by contradiction:}7273\begin{enumerate}74\item Let's assume that $\sqrt{2}$ is rational, meaning it can be written as the ratio of two integers, $a$ and $b$:75\end{enumerate}7677$$78\sqrt{2} = \frac{a}{b}79$$80Where $b \neq 0$ and we assume that $a$ and $b$ have no common factors. If common factors exist, we cancel them in the numerator and denominator.8182\begin{enumerate}[resume]83\item Squaring both sides of the equation gives us:84\end{enumerate}8586$$872 = \frac{a^2}{b^2}88$$8990\begin{enumerate}[resume]91\item Which implies:92\end{enumerate}9394$$95a^2 = 2b^296$$9798\begin{enumerate}[resume]99\item This means that $\sqrt{a}$ must be even, since $\sqrt{a}$ is $2$ multiplied by some number. We know this to be true because the multiplication of two even numbers will always be even.100\item This also means that $a$ itself is even because if $a$ was odd, $a*a$ would be odd as well.101\item Since $a$ is an even number, it is $2$ times another whole number.102\end{enumerate}103104$$105a = 2k106$$107108\begin{enumerate}[resume]109\item If we substitute $a = 2k$ into the squared original equation, we get:110\end{enumerate}111112$$1132 = \frac{(2k)^2}{b^2}114$$115$$1162 = \frac{4k^2}{b^2}117$$118$$1192b^2 = 4k^2120$$121$$122b^2 = 2k^2123$$124125\begin{enumerate}[resume]126\item This means that $b^2$ is even, which follows that $b$ itself is even.127\item \textbf{This is where there is a contradiction.} If $a$ and $b$ are both even numbers, then $\frac{a}{b}$ is not in its simplest form and still has common factors. This is a contradiction because we assumed that the equation was rational and had no common factors from the start. \textbf{Therefore, $\sqrt{2}$ must be irrational.}128\end{enumerate}129130\newpage131132\noindent{\textbf{Continued Fractions:}} \par133134A continued fraction is a fraction of infinite length whose denominator is a quantity plus a fraction, which latter fraction has a similar denominator, and so on. Continued fractions are great ways to express irrational numbers like $e$, $\pi$, and $\sqrt{2}$. \par135136\vspace{0.02cm}{\noindent{Interesting Facts:}}137138\begin{itemize}139\item John Wallis first used the term "continued fraction" in his Arithmetica Infinitorum of 1653.140\item Another word for a continued fraction is anthyphairetic ratio.141\end{itemize}142143\noindent{The basic form of a continued fraction is as follows:}144145$$146a_0 +\cfrac{b_1}{a_1+\cfrac{b_2}{a_2+\cfrac{b_3}{a_3+\cdots}}}147$$148149where $a_n$ and $b_n$ are either rational numbers, real numbers, or complex numbers. If $b_n = 1$ for all $n$ the expression is called a simple continued fraction. If the expression has a finite amount of terms, it is called a finite continued fraction. Similarly, if the expression has an infinite number of terms, it is called an infinite continued fraction.150151\vspace{0.02cm}{$e$ as a continued fraction:}152153$$154e = 2+\cfrac{1}{1+\cfrac{1}{2+\cfrac{2}{3+\cfrac{3}{4+\cdots}}}}155$$156157$\pi$ as a continued fraction:158159$$160\pi = {\cfrac{4}{1+\cfrac{1^2}{3+\cfrac{2^2}{5+\cfrac{3^2}{7+\cfrac{4^2}{9+\cdots}}}}}}161$$162163$\sqrt{2}$ as a continued fraction:164165$$166\sqrt{2} = 1+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cdots}}}}167$$168169\newpage170171\noindent\textbf{{Python Code For Approximating e:}} \par172173Below is the code I wrote to approximate $e$:174175\begin{lstlisting}[language=Python, caption=Estimator for $e$]176n = input("How many decimals of e would you like to approximate?")177178sum = 0179desired_e = N(e, digits = n + 1)180term_number = 0181182while sum != desired_e:183sum += 1/factorial(term_number)184term_number += 1185186print "NOTE: The code will approximate to the " + str(n) + " digits you requested, but it will show " + str(n+1) + " digits to prevent rounding errors."187print "-----------------------------------------------------------"188print "Estimated value of e: " + str(N(sum, digits = n + 1))189print "-----------------------------------------------------------"190print "Actual value of e: " + str(desired_e)191print "-----------------------------------------------------------"192print "Difference: " + str((N(desired_e - sum, digits = 2)))193print "-----------------------------------------------------------"194\end{lstlisting}195196\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par197198The code will ask how many digits of $e$ you would like to approximate and store it in variable $n$. The variable "sum" has an initial value of $0$. While "sum" is not equal to the actual value of $e$ ("desired{\_}e"), the series expansion for $e$ (shown below) will be continuously added to "sum", increasing the "term{\_}number" ($k$) by $1$ integer each time until "sum" does equal "desired{\_}e". When "sum" does equal "desired{\_}e", the code will exit the While loop. The code will then print the value of $e$ estimated with the variable "sum" with $n+1$ digits. Underneath that, the code will print the actual value of $e$ (stored as a constant by SageMathCloud) with the variable "desired{\_}e" with $n+1$ digits. The code will then calculate the difference between the estimated and actual value of $e$ and print that number. NOTE: The difference should always be zero if the code is properly functioning. \par199200\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $e$:}}} \par201202$$203e =\sum ^{\infty }_{k=0}\dfrac{1}{k!}204$$205206\newpage207208\noindent\textbf{{Python Code For Approximating $\sqrt{2}$:}} \par209210Below is the code I wrote to approximate $\sqrt{2}$:211212\begin{lstlisting}[language=Python, caption=Estimator For $\sqrt{2}$]213n_2 = input("How many decimals of sqrt(2) would you like to approximate?")214215sum_2 = 0216desired_2 = N(sqrt(2), digits = n_2 + 1)217term_number_2 = 0218219while sum_2 != desired_2:220sum_2 += (factorial(2*(term_number_2)+1))/((2^(3*(term_number_2)+1))*(factorial(term_number_2))^2)221term_number_2 += 1222223print "NOTE: The code will approximate to the " + str(n_2) + " digits you requested, but it will show " + str(n_2+1) + " digits to prevent rounding errors."224print "-----------------------------------------------------------"225print "Estimated value of 2: " + str(N(sum_2, digits = n_2 + 1))226print "-----------------------------------------------------------"227print "Actual value of 2: " + str(desired_2)228print "-----------------------------------------------------------"229print "Difference: " + str((N(desired_2 - sum_2, digits = 2)))230print "-----------------------------------------------------------"231\end{lstlisting}232233\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par234235The code for approximating $\sqrt{2}$ is essentially the same as the code for approximating $e$. The only difference is in the variables and the series expansions.\par236237\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $\sqrt{2}$:}}} \par238239$$240\sqrt{2} =\sum ^{\infty }_{k=0}\dfrac {\left( 2k+1\right) !}{2^{3k+1}\left( k!\right) ^{2}}241$$242243\newpage244245\noindent\textbf{{Python Code For Approximating $\pi$}} \par246247Below is the code I wrote to approximate $\pi$:248249\begin{lstlisting}[language=Python, caption=Estimator For $\pi$]250n_pi = input("How many decimals of pi would you like to approximate?")251252sum_pi = 0253desired_pi = N(pi, digits = n_pi + 1)254term_number_pi = 0255256while sum_pi != desired_pi:257sum_pi += (1/(16^term_number_pi))*((4/(8*(term_number_pi)+1))-(2/(8*(term_number_pi)+4))-(1/(8*(term_number_pi)+5))-(1/(8*(term_number_pi)+6)))258term_number_pi += 1259260print "NOTE: The code will approximate to the " + str(n_pi) + " digits you requested, but it will show " + str(n_pi+1) + " digits to prevent rounding errors."261print "-----------------------------------------------------------"262print "Estimated value of pi: " + str(N(sum_pi, digits = n_pi + 1))263print "-----------------------------------------------------------"264print "Actual value of pi: " + str(desired_pi)265print "-----------------------------------------------------------"266print "Difference: " + str((N(desired_pi - sum_pi, digits = 2)))267print "-----------------------------------------------------------"268\end{lstlisting}269270\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par271272The code for approximating $\pi$ is essentially the same as the code for approximating $e$ and $\sqrt{2}$. The only difference is in the variables and the series expansions.\par273274\vspace{0.2cm}{\noindent\textbf{{Series Expansion for $\pi$ (Bailey–Borwein–Plouffe Formula):}}} \par275276$$277\pi =\sum ^{\infty }_{k=0}\left[ \dfrac {1}{16^{k}}\left( \dfrac {4}{8k+1}-\dfrac {2}{8k+4}-\dfrac {1}{8k+5}-\dfrac {1}{8k+6}\right) \right]278$$279280Interestingly enough, the code for approximating $\pi$ gave me the most trouble. The series expansions that I had previously used in the code either did not converge fast enough or somehow made the variable "sum{\_}pi" infinitely locked in the While loop. After some research and trial and error, I discovered the Bailey–Borwein–Plouffe Formula and decided to try it. It worked perfectly.281282\newpage283284\section*{Conclusion}285286Overall, this has been my favorite project. The code was fairly challenging and I initially ran into a couple of issues, but this was the first project where I figured the code out on my own. While I went to Mr. Abell when technical issues arose, the basic structure of the code was my own. In addition, this is the first project that I started well in advance of the due date. I usually try to figure the project out the day it is assigned, but then I put it off until the last few days. This time, I had finished the code a week or two before the due date, making it possible for me to write the report without any stress. \par287288I have really enjoyed brushing up my Python skills and learning \LaTeX \space this year, and I hope I can continue to use these tools in the future, whether it be for school or just for fun.289290\end{document}291292