Skip to content

Commit

Permalink
Merge pull request #54 from project-lovelace/warmup-descriptions
Browse files Browse the repository at this point in the history
Warmup descriptions
  • Loading branch information
ali-ramadhan authored Jul 22, 2019
2 parents c346aee + c33e9cf commit e88e79f
Show file tree
Hide file tree
Showing 24 changed files with 669 additions and 232 deletions.
104 changes: 52 additions & 52 deletions src/problems/templates/problems/ada-lovelaces-note-g.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

{% load static %}

{% block useful_to_know %}
basic math operations.
{% block you_will_learn %}
Ada Lovelace, the first computer algorithm, and Bernoulli numbers.
{% endblock %}

{% block problem_body %}
Expand Down Expand Up @@ -35,9 +35,10 @@
<img src="{% static 'img/Diagram_for_the_computation_of_Bernoulli_numbers.jpg' %}">
<figcaption class="help">
Diagram of an algorithm for the Analytical Engine for the computation of Bernoulli numbers, from <i>Sketch of The
Analytical Engine Invented by Charles Babbage by Luigi Menabrea with notes by Ada Lovelace</i>. (Source: <a
href="https://commons.wikimedia.org/wiki/File:Diagram_for_the_computation_of_Bernoulli_numbers.jpg">Wikimedia
Commons</a>)
Analytical Engine Invented by Charles Babbage by Luigi Menabrea with notes by Ada Lovelace</i>. The steps are
describing how the analytical engine would compute $B_8$, which she called $B_7$ in her notation.
(Source: <a href="https://commons.wikimedia.org/wiki/File:Diagram_for_the_computation_of_Bernoulli_numbers.jpg">
Wikimedia Commons</a>)
</figcaption>
</figure>
<br>
Expand Down Expand Up @@ -106,73 +107,72 @@
{% endblock %}

{% block notes_and_references %}
<div class="content">
<div class="content">
<h3>Derivation of Ada Lovelace's algorithm</h3>
To see how Ada derived her formula for the Bernoulli numbers we will have to make use of the fact that $e^t$ can be
expressed as an infinite series $\displaystyle e^t = \sum_{n=0}^\infty \frac{t^n}{n!:}$ which is called its Taylor
series.
<p class="has-text-justified">
To see how Ada derived her formula for the Bernoulli numbers we will have to make use of the fact that $e^t$ can
be expressed as an infinite series $\displaystyle e^t = \sum_{n=0}^\infty \frac{t^n}{n!:}$ which is called its
Taylor series.

The Bernoulli numbers $B_n$ can be defined as the coefficients of the Taylor series of a generating function
The Bernoulli numbers $B_n$ can be defined as the coefficients of the Taylor series of a generating function

$$ \frac{t}{e^t - 1} = \sum_{n=0}^\infty B_n \frac{t^n}{n!} $$
$$ \frac{t}{e^t - 1} = \sum_{n=0}^\infty B_n \frac{t^n}{n!} $$

We now want to solve for $B_n$ to get a formula for the Bernoulli numbers we can use to program a computer. We move
both terms to a single side and insert the Taylor series for $e^t$ to get
We now want to solve for $B_n$ to get a formula for the Bernoulli numbers we can use to program a computer. We
move both terms to a single side and insert the Taylor series for $e^t$ to get

$$ 1 = \frac{e^t - 1}{t} \sum_{n=0}^\infty B_n \frac{t^n}{n!}
= \sum_{m=0}^\infty \frac{x^m}{(m+1)!} \sum_{n=0}^\infty B_n \frac{t^n}{n!} $$
$$ 1 = \frac{e^t - 1}{t} \sum_{n=0}^\infty B_n \frac{t^n}{n!}
= \sum_{m=0}^\infty \frac{x^m}{(m+1)!} \sum_{n=0}^\infty B_n \frac{t^n}{n!} $$

We now have the product of two infinite series so let's expand their product up to terms including $t^4$. This
gives us
We now have the product of two infinite series so let's expand their product up to terms including $t^4$. This
gives us

\begin{align*}
1 &= \left( 1 + \frac{t}{2} + \frac{t^2}{2\cdot3} + \frac{t^3}{2\cdot3\cdot4} + \frac{t^4}{2\cdot3\cdot4\cdot5} +
\mathcal{O}(t^5) \right) \left( B_0 + B_1t + B_2 \frac{t^2}{2} + B_3\frac{t^3}{2\cdot3} +
B_4\frac{t^4}{2\cdot3\cdot4} + \mathcal{O}(t^5) \right) \\
&= B_0 + \left( B_1 + \frac{B_0}{2} \right) t + \left( \frac{B_2}{2} + \frac{B_1}{2} + \frac{B_0}{2\cdot3}
\right)t^2 + \left( \frac{B_3}{2\cdot3} + \frac{B_2}{2\cdot2} + \frac{B_1}{2\cdot3} + \frac{B_0}{2\cdot3\cdot4}
\right) t^3 \\
& \quad + \left( \frac{B_4}{2\cdot3\cdot4} + \frac{B_3}{2\cdot2\cdot3} + \frac{B_2}{2\cdot2\cdot3} +
\frac{B_1}{2\cdot3\cdot4} + \frac{B_0}{2\cdot3\cdot4\cdot5} \right) t^4 + \mathcal{O}(t^5)
\end{align*}
\begin{align*}
1 &= \left( 1 + \frac{t}{2} + \frac{t^2}{2\cdot3} + \frac{t^3}{2\cdot3\cdot4} + \frac{t^4}{2\cdot3\cdot4\cdot5}
+ \mathcal{O}(t^5) \right) \left( B_0 + B_1t + B_2 \frac{t^2}{2} + B_3\frac{t^3}{2\cdot3}
+ B_4\frac{t^4}{2\cdot3\cdot4} + \mathcal{O}(t^5) \right) \\
&= B_0 + \left( B_1 + \frac{B_0}{2} \right) t + \left( \frac{B_2}{2} + \frac{B_1}{2}
+ \frac{B_0}{2\cdot3} \right)t^2 + \left( \frac{B_3}{2\cdot3} + \frac{B_2}{2\cdot2} + \frac{B_1}{2\cdot3}
+ \frac{B_0}{2\cdot3\cdot4} \right) t^3 \\
& \quad + \left( \frac{B_4}{2\cdot3\cdot4} + \frac{B_3}{2\cdot2\cdot3} + \frac{B_2}{2\cdot2\cdot3}
+ \frac{B_1}{2\cdot3\cdot4} + \frac{B_0}{2\cdot3\cdot4\cdot5} \right) t^4 + \mathcal{O}(t^5)
\end{align*}

where we grouped terms with the same powers of $t$.
where we grouped terms with the same powers of $t$.

Now we can start calculating the Bernoulli numbers. The left and right hand sides must be equal so $B_0 = 1$. As $t$
does not appear on the left, we can calculate $B_1$ using
Now we can start calculating the Bernoulli numbers. The left and right hand sides must be equal so $B_0 = 1$. As
$t$ does not appear on the left, we can calculate $B_1$ using

$$ B_1 + \frac{B_0}{2} = 0 \quad \implies \quad B_1 = -\frac{B_0}{2} = -\frac{1}{2} $$
$$ B_1 + \frac{B_0}{2} = 0 \quad \implies \quad B_1 = -\frac{B_0}{2} = -\frac{1}{2} $$

and similarly for $B_2$ as $t^2$ does not appear on the left
and similarly for $B_2$ as $t^2$ does not appear on the left

$$ \frac{B_2}{2} + \frac{B_1}{2} + \frac{B_0}{2\cdot3} \quad \implies \quad B_2 = -2\left( \frac{B_1}{2} +
\frac{B_0}{6} \right) = -2\left( -\frac{1}{4} + \frac{1}{6} \right) = \frac{1}{6} $$
$$ \frac{B_2}{2} + \frac{B_1}{2} + \frac{B_0}{2\cdot3} \quad \implies \quad B_2 = -2\left( \frac{B_1}{2}
+ \frac{B_0}{6} \right) = -2\left( -\frac{1}{4} + \frac{1}{6} \right) = \frac{1}{6} $$

Repeating the process for the $t^3$ and $t^4$ terms we find $B_3 = 0$ and $\displaystyle B_4 = -\frac{1}{30}$. We
also notice a pattern: the coefficient of $t^n$, which is equal to zero, is given by
Repeating the process for the $t^3$ and $t^4$ terms we find $B_3 = 0$ and $\displaystyle B_4 = -\frac{1}{30}$. We
also notice a pattern: the coefficient of $t^n$, which is equal to zero, is given by

\begin{multline}
1\cdot\frac{B_n}{2\cdot3\cdot4\cdots(n+1)} + \frac{1}{2} \cdot \frac{B_{n-1}}{2\cdot3\cdot4\cdots n} +
\frac{1}{2\cdot3} \cdot \frac{B_{n-2}}{2\cdot3\cdot4\cdots (n-1)} + \cdots \\
+ \frac{1}{2\cdot3\cdots(n-2)} \cdot \frac{B_3}{2\cdot3} + \frac{1}{2\cdot3\cdots(n-1)} \cdot \frac{B_2}{2} +
\frac{1}{2\cdot3\cdots n} \cdot B_1 + \frac{1}{2\cdot3\cdots(n+1)} \cdot B_0 = 0
\end{multline}
\begin{multline}
1\cdot\frac{B_n}{2\cdot3\cdot4\cdots(n+1)} + \frac{1}{2} \cdot \frac{B_{n-1}}{2\cdot3\cdot4\cdots n}
+ \frac{1}{2\cdot3} \cdot \frac{B_{n-2}}{2\cdot3\cdot4\cdots (n-1)} + \cdots \\
+ \frac{1}{2\cdot3\cdots(n-2)} \cdot \frac{B_3}{2\cdot3} + \frac{1}{2\cdot3\cdots(n-1)} \cdot \frac{B_2}{2}
+ \frac{1}{2\cdot3\cdots n} \cdot B_1 + \frac{1}{2\cdot3\cdots(n+1)} \cdot B_0 = 0
\end{multline}

which we can write as
which we can write as

$$ \sum_{k=0}^n \frac{1}{(n+1-k)!} \cdot \frac{B_n}{k!} = 0 $$
$$ \sum_{k=0}^n \frac{1}{(n+1-k)!} \cdot \frac{B_n}{k!} = 0 $$

and so if we take out the $B_n$ term we can express it in terms of $B_k$ for $k \lt n$
and so if we take out the $B_n$ term we can express it in terms of $B_k$ for $k \lt n$

$$ B_n = -\sum_{k=0}^{n-1} \frac{n!}{(n+1-k)!\cdot k!} B_k = -\sum_{k=0}^{n-1} \binom{n}{k} \frac{B_k}{n+1-k} $$

Using this formula along with $B_0 = 1$ we can calculate any Bernoulli number $B_n$ as long as we know all the lower
Bernoulli numbers $B_0, B_1, B_2, \dots, B_{n-1}$.
$$ B_n = -\sum_{k=0}^{n-1} \frac{n!}{(n+1-k)!\cdot k!} B_k = -\sum_{k=0}^{n-1} \binom{n}{k} \frac{B_k}{n+1-k} $$

In Ada Lovelace's Note G, she proposes an algorithm for calculating what we call $B_8$, which she labeled $B_7$.
Using our slightly more modern notation Note G is essentially carrying out the following calculation
Using this formula along with $B_0 = 1$ we can calculate any Bernoulli number $B_n$ as long as we know all the
lower Bernoulli numbers $B_0, B_1, B_2, \dots, B_{n-1}$.

$$ B_8 = $$
In Ada Lovelace's Note G, she proposes an algorithm for calculating what we call $B_8$, which she labeled $B_7$.
</p>

<h3>Notes</h3>
<ul>
Expand Down
47 changes: 35 additions & 12 deletions src/problems/templates/problems/almost-pi.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@

{% load static %}

{% block useful_to_know %}
loops, summation, pi is everywhere.
{% block you_will_learn %}
loops, summation, and 🥧.
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
The number π=3.1415926535897... is the ratio of a circle's circumference to its diameter and shows up absolutely
everywhere in math and science. It's decimal expansion goes on forever but we can actually calculate it by summing up
a bunch of fractions
The number $\pi$=3.1415926535897... is the ratio of a circle's circumference to its diameter and shows basically
everywhere in math and science. It's like the most famous number in math. It's decimal expansion goes on forever but
we can actually calculate it by summing up a bunch of fractions

$$ \frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + \dots
= \sum_{k=0}^n \frac{(-1)^k}{2k+1} $$

By adding more and more terms, you get a better and better approximation to π.
By adding more and more terms, you get a better and better approximation to $\pi$. Given the number of terms $n$,
sum the first $n$ terms and return the result.
</p>

<br>
<figure style="text-align: center;">
<img src="{% static 'img/approximating_pi.png' %}">
<figcaption class="help">
The blue line shows the sum of the first $n$ terms for $0 \le n \le 50$ while the orange dashed line shows the exact
value of $\pi$. By adding each term, you end up overestimating then underestimating $\pi$, but it slowly converges to the
exact value.
</figcaption>
</figure>
<br>
{% endblock %}

{% block input_description %}
The number of terms to use in calculating π.
An integer $n$ for the number of terms to sum in calculating $\pi$ using the above equation.
{% endblock %}

{% block output_description %}
The approximation to π.
The sum of the first $n$ terms giving an approximation to $\pi$.
{% endblock %}

{% block examples %}
Expand Down Expand Up @@ -62,9 +68,17 @@
{% endblock %}

{% block javascript_code_stub %}
function almost_pi(N) {
// Your code goes here!
return 0
}
{% endblock %}

{% block julia_code_stub %}
function almost_pi(N)
# Your code goes here!
return 0
end
{% endblock %}

{% block notes_and_references %}
Expand All @@ -74,7 +88,7 @@ <h3>Solution notes</h3>
<ul>
<li>
The formula we used here is <a href="https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80">Leibniz formula
for π</a> and is one of the slowest to converge: you need TONS of terms to calculate more and more digits of π.
for $\pi$</a> and is one of the slowest to converge: you need TONS of terms to calculate more and more digits of $\pi$.
There are <a href="https://en.wikipedia.org/wiki/List_of_formulae_involving_%CF%80#Efficient_infinite_series">
crazy looking efficient formulas</a>a that can calculate digits of π much faster.
</li>
Expand All @@ -87,13 +101,22 @@ <h3>Solution notes</h3>
</ul>
{% endif %}

<h3>Videos</h3>
<dl>
<dt>
<a href="https://www.youtube.com/watch?v=bcPTiiiYDs8">How pi was almost 6.283185...</a>, 3Blue1Brown
</dt>
</dl>

<h3>Notes</h3>
<ul>
<li>Pi is a transcendental number and its digital expansion contains...</li>
<li>Beautiful visualization</li>
<li>$\pi$ is a transcendental number and its digital expansion contains all possible numbers. 123456789 first shows
up at the 523,551,502nd decimal place! You can search through the first billion digits at
<a href="https://three.onefouronefive.net/">A Billion Digits of Pi</a>.
</li>
</ul>
</div>
{% endblock %}

{% block discourse_topic_id %}xx{% endblock %}
{% block discourse_topic_id %}262{% endblock %}

77 changes: 59 additions & 18 deletions src/problems/templates/problems/babylonian-square-roots.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,54 @@

{% load static %}

{% block useful_to_know %}
numerical algorithms.
{% block you_will_learn %}
calculating square roots, iterative algorithms, and Babylonian math.
{% endblock %}

{% block problem_body %}
<p class="has-text-justified">
The basic idea is to start with a guess $x_0$ for $\sqrt{S}$. Then we can improve on this guess: if $x_n$ is an
overestimate to $\sqrt{S}$ then $S/x_n$ will be an underestimate, so averaging the two should produce a better guess:
The square root of a number S is denoted $\sqrt{S}$ with the property that $\sqrt{S} \times \sqrt{S} = S$. It's easy
to calculate for square numbers, like $3 \times 3 = 9$ so $\sqrt{9} = 3$. For other numbers it's not as easy but the
ancient Babylonians seemed to know how to calculate them pretty accurately (see the figure and caption).
</p>
<br>

<p class="has-text-justified">
We have no idea how they calculated square roots so accurately, but a method they might have used has been called the
Babylonian method.

The basic idea is to start with an initial guess $x_0$ for $\sqrt{S}$. Then we can keep improve on this guess: if
our current guess, $x_n$, is an overestimate to $\sqrt{S}$ then $S/x_n$ will be an underestimate and vice versa, so
averaging the two should produce a better guess:

$$ x_{n+1} = \frac{1}{2} \left( x_n + \frac{S}{x_n} \right) $$

We can use this formula to calculate better and better guesses. Given a number $S$, calculate and return its square
root using the Babylonian method.
</p>

<br><br>
<br>
<figure style="text-align: center;">
<img src="{% static 'img/YBC7289.jpg' %}">
<figcaption class="help">
A photograph of the Babylonian clay tablet <a href="https://en.wikipedia.org/wiki/YBC_7289">YBC 7289</a>. The
numbers on the diagonal are actually a pretty accurate approximation of $\sqrt{2}$. They read in sexagesimal
(base 60) 1, 24, 51, and 10 which cooresponds to $\sqrt{2} \approx 1 + 24/60 + 51/60^2 + 10/60^3 = 1.41421296...$
which is correct to six decimal digits! It also shows a square with sides of length 30 and diagonal of length
$30 \sqrt{2} \approx 42 + 25/60 + 35/60^2$.
(Source: <a href="https://commons.wikimedia.org/wiki/File:YBC-7289-OBV-labeled.jpg">Wikimedia Commons</a>)
</figcaption>
</figure>
<br>
{% endblock %}

{% block input_description %}
A number.
A number $S$.
{% endblock %}

{% block output_description %}
It's square root approximated using the babylonian method.
The square root of $S$ approximated using the babylonian method. If $S$ is a negative number, then return the string
"undefined".
{% endblock %}

{% block examples %}
Expand Down Expand Up @@ -57,32 +81,49 @@
{% endblock %}

{% block javascript_code_stub %}
function babylonian_sqrt(S) {
# Your code goes here!
return 0
}
{% endblock %}

{% block julia_code_stub %}
function babylonian_sqrt(S)
# Your code goes here!
return 0
end
{% endblock %}

{% block notes_and_references %}
<div class="content">
{% if solved_by_user %}
<h3>Solution notes</h3>
<ul>
<li></li>
</ul>
{% endif %}

<h3>Notes</h3>
<ul>
<li></li>
<li>
The method we used here is also called Heron's method after the Hero of Alexandria who explicitly described it
in 60 AD.
</li>
<li>
The Babylonians did lots of other cool stuff that was way ahead of their time like
<a href="https://science.sciencemag.org/content/351/6272/482">
calculate Jupiter’s position from the area under a time-velocity graph
</a>.
</li>
</ul>

<h3>References</h3>
<dl>
<dt></dt>
<dd></dd>
<dt>
<a href="https://johncarlosbaez.wordpress.com/2011/12/02/babylon-and-the-square-root-of-2/">Babylon and the
square root of 2</a>, The Azimuth Project
</dt>
<dt>
<a href="https://www.sciencedirect.com/science/article/pii/S0315086098922091?via%3Dihub">
Square Root Approximations in Old Babylonian Mathematics: YBC 7289 in Context
</a>, David Fowler & Eleanor Robson, Historia Mathematica, Volume 25, Issue 4, pp. 366-378 (1998).
</dt>
</dl>
</div>
{% endblock %}

{% block discourse_topic_id %}xx{% endblock %}
{% block discourse_topic_id %}265{% endblock %}

Loading

0 comments on commit e88e79f

Please sign in to comment.