Pi
Day – Euler’s Infinite Expansion of Pi
Most
people know that pi is a number that is infinite and non-repeating
i.e. it never ends and there is no repeating pattern to it. Numbers
like these are known as irrational or transcendental, depending on
the type of equation that can be solved by them. Pi is actually
transcendental, though it took a long time for that to be proved
mathematically.
Though
pi is known by most people as the ratio of a circle’s radius (or
diameter) to its circumference, it actually turns up all over the
place in mathematics. One of these places is as the solution to
infinite series, of which many have been discovered.
A
famous result was discovered by the mathematician Leonard Euler, in
1734. It says:
1 + 1/22
+ 1/32
+ 1/42
+ 1/52
+ … = pi2/6
In other words, if you take all of the integers
and square their reciprocals, then add them up, the answer will be
exactly equal to pi squared divided by 6.
A related result can be derived for the even
integers:
1 + 1/22
+ 1/42
+ 1/62
+ 1/82
+ … = pi2/24
For the odd integers:
1 + 1/32
+ 1/52
+ 1/72
+ 1/92
+ … = pi2/8
All of these
results can be proved analytically, though you have to know some
calculus, as the proofs involve integrals. Rather than do this, I
set up some R code to explore the expansions, and see how close they
come to the value of pi.
There are a few obvious cautions,
both involving infinity:
-
We can’t actually add up an infinite number
of terms, so we can never get the exact sum for the various series.
-
We don’t actually know the exact value of pi
(and can’t ever know it), so we can’t actually do the
comparisons.
-
Computers will run into problems with floating
point operations as the numbers become very large or very small.
Nonetheless, even a modest laptop computer can
provide some interesting results, as shown below:
The top table shows show:
-
the number of terms in each trial of the
expansion (from 10 to one hundred million),
-
the actual value of pi (as approximated by
the R program),
-
the value of pi using all integers from1to
the upper limit of terms,
-
the value of pi using the first “limit”
number of even integers,
-
he value of pi using the first “limit”
number of oddintegers
The second table is similar, but it shows the
difference between R’s value of pi and the value computed by the
expansions, expressed in parts per billion.
As you can see,
the value that most of us routinely use (3.14) is well approximated
after about 1000 terms of these series. For those of us that like to
be a little more precise and remember the value to five decimal
places (3.14159), on the order of 100,000 terms is needed.
Eventually, by 100,000,000 terms in the
expansions, the difference between R’s “true” value of pi and
our expansion approximation is down to less than 10 parts per
billion. Thinking of that in more everyday terms:
-
If you drew a circle 1,000 km in diameter, 1
part in a billion is about 1 mm.
-
In a circle of 360 degrees, 1 part in a
billion is about one-thousandth of an arc-second. The
resolution of the Hubble space telescope is about one-twentieth of
an arc-second.
-
If you had a pumpkin pie that weighed 1
kilogram, 1 part in a billion would be about 1 microgram. A
particle of the pie that was one-tenth of a millimeter in diameter
would weight about that much.
A couple of interesting results that I wasn’t
expecting, are that the sum of odd integers converges faster than the
sum of even integers, and even converges faster than the sum of all
integers. Also, the “all integers” and the even integers
converge at the same rate. So, by 100 million terms, the odd
integers have converged to within 3 parts per billion, while the
other two are still at about 9 parts per million.
Those results definitely seem
counter-intuitive, but I can’t see anything wrong with my R code
(given below). It is something to think about, and shows how math
sometimes gives results that seem strange, at least at first sight.
Sources:
Inside Interesting Integrals, Paul Nahin,
Springer (p 154-55)
Here is some
R code that you can run and experiment with, to see for yourself:
#
-----------------------------------------------------------
# R program to estimate pi from Euler's
formula,
# that uses an infinite series.
#
---------------------------------------------------------
ls()
options(digits = 11)
# the dataframe is intialized with the
first, short expansion.
limit <- 10
# All integers
pi_est_all <- seq(1, limit, 1)
pi_est_all$a <-
1/(pi_est_all*pi_est_all)
pi_all <- sqrt(6*sum(pi_est_all$a))
pi_all
# Even integers
pi_est_even <- seq(2, limit*2, 2)
#pi_est_even
pi_est_even$a <-
1/(pi_est_even*pi_est_even)
pi_even <-
sqrt(24*sum(pi_est_even$a))
pi_even
# Odd integers
pi_est_odd <- seq(1, limit*2+1, 2)
#pi_est_odd
pi_est_odd$a <-
1/(pi_est_odd*pi_est_odd)
pi_odd <- sqrt(8*sum(pi_est_odd$a))
pi_odd
pi_init <- cbind(limit, pi, pi_all,
pi_even, pi_odd)
pi_init
pi_est2 <- pi_init
pi_est2
# Loops through, with other limits for
the expansion. This increases the limit
# by a factor of 10, for each trip
through the loop. The limits and increments
# can be changed. Computer will run
out of memory at some point.
limit <- 100
while(limit < 1000000000)
{
# All integers
pi_est_all <- seq(1, limit, 1)
pi_est_all$a <-
1/(pi_est_all*pi_est_all)
pi_all <- sqrt(6*sum(pi_est_all$a))
pi_all
rm(pi_est_all)
# Even integers
pi_est_even <- seq(2, 2*limit, 2)
#pi_est_even
pi_est_even$a <-
1/(pi_est_even*pi_est_even)
pi_even <-
sqrt(24*sum(pi_est_even$a))
#pi_even
rm(pi_est_even)
# Odd integers
pi_est_odd <- seq(1, 2*limit+1, 2)
#pi_est_odd
pi_est_odd$a <-
1/(pi_est_odd*pi_est_odd)
pi_odd <- sqrt(8*sum(pi_est_odd$a))
#pi_odd
rm(pi_est_odd)
pi_est <- cbind(limit, pi, pi_all,
pi_even, pi_odd)
pi_est2<-rbind(pi_est2, pi_est)
limit <- limit * 10
}
# Convert to a data frame and print
results.
pi_est_df <- as.data.frame(pi_est2)
pi_est_df
ls()
And,
here
are some earlier blogs about pi, where it shows up in
other areas of math, namely geometry, statistics and number theory.
https://dodecahedronbooks.blogspot.com/2020/03/pi-day-2020-pi-and-normal-distribution.html
https://dodecahedronbooks.blogspot.com/2019/03/pi-day-2019-shooting-arrows-at-target.html
https://dodecahedronbooks.blogspot.com/2018/03/pi-day-2018-prime-numbers-and-pi.html
https://dodecahedronbooks.blogspot.com/2017/03/pi-day-floor-pie-and-floor-pi.html
https://dodecahedronbooks.blogspot.com/2016/03/pi-day-31416-some-eerie-pi-coincidences.html
https://dodecahedronbooks.blogspot.com/2015/03/pi-day-31415-pi-and-science-fiction.html
So,
now that you have done some math, you should read a science fiction
book, or even better, a whole series. Book 1 of the Witches’
Stones series even includes a reference to pi.:
Kati of Terra
How about trying Kati of
Terra, the 3-novel story of a feisty young Earth woman, making her
way in that big, bad, beautiful universe out there.
http://www.amazon.com/gp/product/B00811WVXO
http://www.amazon.co.uk/gp/product/B00811WVXO
The Witches’ Stones
Or,
you might prefer, the trilogy of the Witches’ Stones (they’re
psychic aliens, not actual witches), which follows the interactions
of a future Earth confederation, an opposing galactic power, and the
Witches of Kordea. It features Sarah Mackenzie, another feisty young
Earth woman (they’re the most interesting type – the novelist who
wrote the books is pretty feisty, too).
https://www.amazon.com/dp/B008PNIRP4
https://www.amazon.co.uk/dp/B008PNIRP4
The Magnetic Anomaly: A Science Fiction Story
“A
geophysical crew went into the Canadian north. There were some
regrettable accidents among a few ex-military who had become
geophysical contractors after their service in the forces. A young
man and young woman went temporarily mad from the stress of seeing
that. They imagined things, terrible things. But both are known to
have vivid imaginations; we have childhood records to verify that. It
was all very sad. That’s the official story.”
https://www.amazon.com/dp/B0176H22B4
https://www.amazon.co.uk/dp/B0176H22B4