Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Carson Witt

2061 views
1
\documentclass{article}
2
3
% set font encoding for PDFLaTeX or XeLaTeX
4
\usepackage{ifxetex}
5
\ifxetex
6
\usepackage{fontspec}
7
\else
8
\usepackage[T1]{fontenc}
9
\usepackage[utf8]{inputenc}
10
\usepackage{lmodern}
11
\fi
12
13
% used in maketitle
14
\title{Irrational Numbers Project}
15
\author{Carson Witt}
16
17
\usepackage{amsmath}
18
\usepackage{lipsum}
19
\usepackage{enumitem}
20
\usepackage{listings}
21
\usepackage{color}
22
23
\definecolor{codegreen}{rgb}{0,0.6,0}
24
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
25
\definecolor{codepurple}{rgb}{0.58,0,0.82}
26
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
27
28
\lstdefinestyle{mystyle}{
29
backgroundcolor=\color{white},
30
commentstyle=\color{codegreen},
31
keywordstyle=\color{magenta},
32
numberstyle=\tiny\color{codegray},
33
stringstyle=\color{codepurple},
34
basicstyle=\footnotesize,
35
breakatwhitespace=false,
36
breaklines=true,
37
captionpos=b,
38
keepspaces=true,
39
numbers=left,
40
numbersep=5pt,
41
showspaces=false,
42
showstringspaces=false,
43
showtabs=false,
44
tabsize=2
45
}
46
47
\lstset{style=mystyle}
48
49
% Enable SageTeX to run SageMath code right inside this LaTeX file.
50
% documentation: http://mirrors.ctan.org/macros/latex/contrib/sagetex/sagetexpackage.pdf
51
% \usepackage{sagetex}
52
53
\begin{document}
54
\maketitle
55
56
\section*{Abstract}
57
58
\noindent{\textbf{Introduction:}}
59
60
An 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. \par
61
62
\noindent{\textbf{History:}}
63
64
According 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." \par
65
66
\noindent{\textbf{Task For This Project:}}
67
68
In 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.
69
70
\section*{Context/Work}
71
72
\textbf{Proving that $\sqrt{2}$ is irrational by contradiction:}
73
74
\begin{enumerate}
75
\item Let's assume that $\sqrt{2}$ is rational, meaning it can be written as the ratio of two integers, $a$ and $b$:
76
\end{enumerate}
77
78
$$
79
\sqrt{2} = \frac{a}{b}
80
$$
81
Where $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.
82
83
\begin{enumerate}[resume]
84
\item Squaring both sides of the equation gives us:
85
\end{enumerate}
86
87
$$
88
2 = \frac{a^2}{b^2}
89
$$
90
91
\begin{enumerate}[resume]
92
\item Which implies:
93
\end{enumerate}
94
95
$$
96
a^2 = 2b^2
97
$$
98
99
\begin{enumerate}[resume]
100
\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.
101
\item This also means that $a$ itself is even because if $a$ was odd, $a*a$ would be odd as well.
102
\item Since $a$ is an even number, it is $2$ times another whole number.
103
\end{enumerate}
104
105
$$
106
a = 2k
107
$$
108
109
\begin{enumerate}[resume]
110
\item If we substitute $a = 2k$ into the squared original equation, we get:
111
\end{enumerate}
112
113
$$
114
2 = \frac{(2k)^2}{b^2}
115
$$
116
$$
117
2 = \frac{4k^2}{b^2}
118
$$
119
$$
120
2b^2 = 4k^2
121
$$
122
$$
123
b^2 = 2k^2
124
$$
125
126
\begin{enumerate}[resume]
127
\item This means that $b^2$ is even, which follows that $b$ itself is even.
128
\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.}
129
\end{enumerate}
130
131
\newpage
132
133
\noindent{\textbf{Continued Fractions:}} \par
134
135
A 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}$. \par
136
137
\vspace{0.02cm}{\noindent{Interesting Facts:}}
138
139
\begin{itemize}
140
\item John Wallis first used the term "continued fraction" in his Arithmetica Infinitorum of 1653.
141
\item Another word for a continued fraction is anthyphairetic ratio.
142
\end{itemize}
143
144
\noindent{The basic form of a continued fraction is as follows:}
145
146
$$
147
a_0 +\cfrac{b_1}{a_1+\cfrac{b_2}{a_2+\cfrac{b_3}{a_3+\cdots}}}
148
$$
149
150
where $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.
151
152
\vspace{0.02cm}{$e$ as a continued fraction:}
153
154
$$
155
e = 2+\cfrac{1}{1+\cfrac{1}{2+\cfrac{2}{3+\cfrac{3}{4+\cdots}}}}
156
$$
157
158
$\pi$ as a continued fraction:
159
160
$$
161
\pi = {\cfrac{4}{1+\cfrac{1^2}{3+\cfrac{2^2}{5+\cfrac{3^2}{7+\cfrac{4^2}{9+\cdots}}}}}}
162
$$
163
164
$\sqrt{2}$ as a continued fraction:
165
166
$$
167
\sqrt{2} = 1+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cfrac{1}{2+\cdots}}}}
168
$$
169
170
\newpage
171
172
\noindent\textbf{{Python Code For Approximating e:}} \par
173
174
Below is the code I wrote to approximate $e$:
175
176
\begin{lstlisting}[language=Python, caption=Estimator for $e$]
177
n = input("How many decimals of e would you like to approximate?")
178
179
sum = 0
180
desired_e = N(e, digits = n + 1)
181
term_number = 0
182
183
while sum != desired_e:
184
sum += 1/factorial(term_number)
185
term_number += 1
186
187
print "NOTE: The code will approximate to the " + str(n) + " digits you requested, but it will show " + str(n+1) + " digits to prevent rounding errors."
188
print "-----------------------------------------------------------"
189
print "Estimated value of e: " + str(N(sum, digits = n + 1))
190
print "-----------------------------------------------------------"
191
print "Actual value of e: " + str(desired_e)
192
print "-----------------------------------------------------------"
193
print "Difference: " + str((N(desired_e - sum, digits = 2)))
194
print "-----------------------------------------------------------"
195
\end{lstlisting}
196
197
\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par
198
199
The 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. \par
200
201
\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $e$:}}} \par
202
203
$$
204
e =\sum ^{\infty }_{k=0}\dfrac{1}{k!}
205
$$
206
207
\newpage
208
209
\noindent\textbf{{Python Code For Approximating $\sqrt{2}$:}} \par
210
211
Below is the code I wrote to approximate $\sqrt{2}$:
212
213
\begin{lstlisting}[language=Python, caption=Estimator For $\sqrt{2}$]
214
n_2 = input("How many decimals of sqrt(2) would you like to approximate?")
215
216
sum_2 = 0
217
desired_2 = N(sqrt(2), digits = n_2 + 1)
218
term_number_2 = 0
219
220
while sum_2 != desired_2:
221
sum_2 += (factorial(2*(term_number_2)+1))/((2^(3*(term_number_2)+1))*(factorial(term_number_2))^2)
222
term_number_2 += 1
223
224
print "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."
225
print "-----------------------------------------------------------"
226
print "Estimated value of 2: " + str(N(sum_2, digits = n_2 + 1))
227
print "-----------------------------------------------------------"
228
print "Actual value of 2: " + str(desired_2)
229
print "-----------------------------------------------------------"
230
print "Difference: " + str((N(desired_2 - sum_2, digits = 2)))
231
print "-----------------------------------------------------------"
232
\end{lstlisting}
233
234
\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par
235
236
The 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.\par
237
238
\vspace{0.2cm}{\noindent\textbf{{Series Expansion Used for $\sqrt{2}$:}}} \par
239
240
$$
241
\sqrt{2} =\sum ^{\infty }_{k=0}\dfrac {\left( 2k+1\right) !}{2^{3k+1}\left( k!\right) ^{2}}
242
$$
243
244
\newpage
245
246
\noindent\textbf{{Python Code For Approximating $\pi$}} \par
247
248
Below is the code I wrote to approximate $\pi$:
249
250
\begin{lstlisting}[language=Python, caption=Estimator For $\pi$]
251
n_pi = input("How many decimals of pi would you like to approximate?")
252
253
sum_pi = 0
254
desired_pi = N(pi, digits = n_pi + 1)
255
term_number_pi = 0
256
257
while sum_pi != desired_pi:
258
sum_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)))
259
term_number_pi += 1
260
261
print "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."
262
print "-----------------------------------------------------------"
263
print "Estimated value of pi: " + str(N(sum_pi, digits = n_pi + 1))
264
print "-----------------------------------------------------------"
265
print "Actual value of pi: " + str(desired_pi)
266
print "-----------------------------------------------------------"
267
print "Difference: " + str((N(desired_pi - sum_pi, digits = 2)))
268
print "-----------------------------------------------------------"
269
\end{lstlisting}
270
271
\vspace{0.2cm}{\noindent\textbf{{Explanation:}}} \par
272
273
The 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.\par
274
275
\vspace{0.2cm}{\noindent\textbf{{Series Expansion for $\pi$ (Bailey–Borwein–Plouffe Formula):}}} \par
276
277
$$
278
\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]
279
$$
280
281
Interestingly 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.
282
283
\newpage
284
285
\section*{Conclusion}
286
287
Overall, 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. \par
288
289
I 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.
290
291
\end{document}
292