Feed john-d-cook John D. Cook

Favorite IconJohn D. Cook

Link https://www.johndcook.com/blog
Feed http://feeds.feedburner.com/TheEndeavour?format=xml
Updated 2024-11-24 02:01
Separable functions in different contexts
I was skimming through the book Mathematical Reflections [1] recently. He was discussing a set of generalizations [2] of the Star of David theorem from combinatorics. The theorem is so named because if you draw a Star of David by connecting points in Pascal's triangle then each side corresponds to the vertices of a triangle. [...]The post Separable functions in different contexts first appeared on John D. Cook.
Body roundness index
Body Roundness Index (BRI) is a proposed replacement for Body Mass Index (BMI) [1]. Some studies have found that BRI is a better measure of obesity and a more effective predictor of some of the things BMI is supposed to predict [2]. BMI is based on body mass and height, and so it cannot distinguish [...]The post Body roundness index first appeared on John D. Cook.
A couple more variations on an ancient theme
I've written a couple posts on the approximation by the Indian astronomer Aryabhata (476-550). The approximation is accurate for x in [-/2, /2]. The first post collected a Twitter thread about the approximation into a post. The second looked at how far the coefficients in Aryabhata's approximation are from the optimal approximation as a ratio [...]The post A couple more variations on an ancient theme first appeared on John D. Cook.
Finding pi in the alphabet
Write the letters of the alphabet around a circle, then strike out the letters that are symmetrical about a vertical line. The remaining letters are grouped in clumps of 3, 1, 4, 1, and 6 letters. I've heard that this observation is due to Martin Gardner, but I don't have a specific reference. In case [...]The post Finding pi in the alphabet first appeared on John D. Cook.
Optimal rational approximation
A few days ago I wrote about the approximation for cosine due to the Indian astronomer Aryabhata (476-550) and gave this plot of the error. I said that Aryabhata's approximation is not quite optimal since the ripples in the error function are not of equal height." This was an allusion to the equioscillation theorem. Chebyshev [...]The post Optimal rational approximation first appeared on John D. Cook.
Pell is to silver as Fibonacci is to gold
As mentioned in the previous post, the ratio of consecutive Fibonacci numbers converges to the golden ratio. Is there a sequence whose ratios converge to the silver ratio the way ratios of Fibonacci numbers converge to the golden ratio? (If you're not familiar with the silver ratio, you can read more about it here.) The [...]The post Pell is to silver as Fibonacci is to gold first appeared on John D. Cook.
Miles to kilometers
The number of kilometers in a mile is k = 1.609344 which is close to the golden ratio = 1.6180334. The ratio of consecutive Fibonacci numbers converges to , and so you can approximately convert miles to kilometers by multiplying by a Fibonacci number and dividing by the previous Fibonacci number. For example, you [...]The post Miles to kilometers first appeared on John D. Cook.
Ancient accurate approximation for sine
This post started out as a Twitter thread. The text below is the same as that of the thread after correcting an error in the first part of the thread. I also added a footnote on a theorem the thread alluded to. *** The following approximation for sin(x) is remarkably accurate for 0 < x [...]The post Ancient accurate approximation for sine first appeared on John D. Cook.
Mentally multiply by π
This post will give three ways to multiply by taken from [1]. Simplest approach Here's a very simple observation about : 3 + 0.14 + 0.0014. So if you need to multiply by , you need to multiply by 3 and by 14. Once you've multiplied by 14 once, you can [...]The post Mentally multiply by first appeared on John D. Cook.
A better integral for the normal distribution
For a standard normal random variable Z, the probability that Z exceeds some cutoff z is given by If you wanted to compute this probability numerically, you could obviously evaluate its defining integral numerically. But as is often the case in numerical analysis, the most obvious approach is not the best approach. The range of [...]The post A better integral for the normal distribution first appeared on John D. Cook.
Drawing with a compass on a globe
Take a compass and draw a circle on a globe. Then take the same compass, opened to the same width, and draw a circle on a flat piece of paper. Which circle has more area? If the circle is small compared to the radius of the globe, then the two circles will be approximately equal [...]The post Drawing with a compass on a globe first appeared on John D. Cook.
The negative binomial distribution and Pascal’s triangle
The Poisson probability distribution gives a simple, elegant model for count data. You can even derive from certain assumptions that data must have a Poisson distribution. Unfortunately reality doesn't often go along with those assumptions. A Poisson random variable with mean also has variance . But it's often the case that data that would [...]The post The negative binomial distribution and Pascal's triangle first appeared on John D. Cook.
A strange take on the harmonic series
It is well known that the harmonic series 1 + + + 1/4 + ... diverges. But if you take the denominators as numbers in base 11 or higher, the series converges [1]. I wonder what inspired this observation. Maybe Brewster was bored, teaching yet another cohort of students that the harmonic series [...]The post A strange take on the harmonic series first appeared on John D. Cook.
Variance matters more than mean in the extremes
Suppose you have two normal random variables, X and Y, and that the variance of X is less than the variance of Y. Let M be an equal mixture of X and Y. That is, to sample from M, you first chose X or Y with equal probability, then you choose a sample from the [...]The post Variance matters more than mean in the extremes first appeared on John D. Cook.
Increasing speed due to friction
Orbital mechanics is fascinating. I've learned a bit about it for fun, not for profit. I seriously doubt Elon Musk will ever call asking me to design an orbit for him. [1] One of the things that makes orbital mechanics interesting is that it can be counter-intuitive. For example, atmospheric friction can make a satellite [...]The post Increasing speed due to friction first appeared on John D. Cook.
Ptolemy’s theorem
Draw a quadrilateral by pick four arbitrary points on a circle and connecting them cyclically. Now multiply the lengths of the pairs of opposite sides. In the diagram below this means multiplying the lengths of the two horizontal-ish blue sides and the two vertical-ish orange sides. Ptolemy's theorem says that the sum of the two [...]The post Ptolemy's theorem first appeared on John D. Cook.
Rule for converting trig identities into hyperbolic identities
There is a simple rule of thumb for converting between (circular) trig identities and hyperbolic trig identities known as Osborn's rule: stick an h on the end of trig functions and flip signs wherever two sinh functions are multiplied together. Examples For example, the circular identity sin( + ) = sin() cos() + cos() sin() [...]The post Rule for converting trig identities into hyperbolic identities first appeared on John D. Cook.
Interpolation and the cotanc function
This weekend I wrote three posts related to interpolation: Compression and interpolation Bessel, Everett, and Lagrange interpolation Binomial coefficients with non-integer arguments The first post looks at reducing the size of mathematical tables by switching for linear to quadratic interpolation. The immediate application is obsolete, but the principles apply to contemporary problems. The second post [...]The post Interpolation and the cotanc function first appeared on John D. Cook.
Binomial coefficients with non-integer arguments
When n and r are positive integers integers, with n >= r, there is an intuitive interpretation of the binomial coefficient C(n, r), namely the number of ways to select r things from a set of n things. For this reason C(n, r) is usually pronounced n choose r." But what might something like C(4.3, [...]The post Binomial coefficients with non-integer arguments first appeared on John D. Cook.
Bessel, Everett, and Lagrange interpolation
I never heard of Bessel or Everett interpolation until long after college. I saw Lagrange interpolation several times. Why Lagrange and not Bessel or Everett? First of all, Bessel interpolation and Everett interpolation are not different kinds of interpolation; they are different algorithms for carrying out the same interpolation as Lagrange. There is a unique [...]The post Bessel, Everett, and Lagrange interpolation first appeared on John D. Cook.
Compression and interpolation
Data compression is everywhere. We're unaware of it when it is done well. We only become aware of it when it is pushed too far, such as when a photo looks grainy or fuzzy because it was compressed too much. The basic idea of data compression is to not transmit the raw data but to [...]The post Compression and interpolation first appeared on John D. Cook.
Chebyshev polynomials as distorted cosines
Forman Acton's book Numerical Methods that Work describes Chebyschev polynomials as cosine curves with a somewhat disturbed horizontal scale, but the vertical scale has not been touched. The relation between Chebyshev polynomials and cosines is Tn(cos ) = cos(n). Some sources take this as the definition of Chebyshev polynomials. Other sources define the polynomials differently [...]The post Chebyshev polynomials as distorted cosines first appeared on John D. Cook.
Math’s base 32 versus Linux’s base 32
The convention in math for writing numbers in bases larger than 10 is to insert capital letters after 9, starting with A. So, for example, the digits in base 12 are 0, 1, 2, ..., 9, A, and B. So if you're familiar with math but not Linux, and you run across the base32 utility, [...]The post Math's base 32 versus Linux's base 32 first appeared on John D. Cook.
Editing a file without an editor
I don't use sed very often, but it's very handy when I do use it, particularly when needing to make a small change to a large file. Fixing a JSON file Lately I've been trying to fix a 30 MB JSON file that has been corrupted somehow. The file is one very long line. Emacs [...]The post Editing a file without an editor first appeared on John D. Cook.
Interpolating the gamma function
Suppose you wanted to approximate (10.3). You know it's somewhere between (10) = 9! and (11) = 10!, and linear interpolation would give you (10.3) 0.7 * 9! + 0.3 * 10! = 1342656. But the exact value is closer to 716430.69, and so our estimate is 53% too high. Not a very good [...]The post Interpolating the gamma function first appeared on John D. Cook.
Too clever Monte Carlo
One way to find the volume of a sphere would be to imagine the sphere in a box, randomly select points in the box, and count how many of these points fall inside the sphere. In principle this would work in any dimension. The problem with naive Monte Carlo We could write a program to [...]The post Too clever Monte Carlo first appeared on John D. Cook.
Evaluating a class of infinite sums in closed form
The other day I ran across the surprising identity and wondered how many sums of this form can be evaluated in closed form like this. Quite a few it turns out. Sums of the form evaluate to a rational number when k is a non-negative integer and c is a rational number with |c| > [...]The post Evaluating a class of infinite sums in closed form first appeared on John D. Cook.
Sphere spilling out
Center a small blue sphere on every corner of ann-dimensional unit hypercube. These are the points in n for which every coordinate is either a 0 or a 1. Now inflate each of these small spheres at the same time until they touch. Each sphere will have radius 1/2. For example, the spheres centered at [...]The post Sphere spilling out first appeared on John D. Cook.
A variation on Rock, Paper, Scissors
Imagine in a game of Rock, Paper, Scissors one player is free to play as usual but the other is required to choose each option the same number of times. That is, in 3n rounds of the game, the disadvantaged player much choose Rock n times, Paper n times, and Scissors n times. Obviously the [...]The post A variation on Rock, Paper, Scissors first appeared on John D. Cook.
q-analog of rising powers
The previous post looked at the probability that a random n by n matrix over a finite field of order q is invertible. This works out to be This function of q and n comes up in other contexts as well and has a name that we will get to shortly. Pochhammer symbols Leo August [...]The post q-analog of rising powers first appeared on John D. Cook.
Solvability of linear systems over finite fields
If you haven equations in n unknowns over a finite field with q elements, how likely is it that the system of equations has a solution? The number of possible n * n matrices with entries from a field of size q is qn^2. The set of invertible n * n matrices over a field [...]The post Solvability of linear systems over finite fields first appeared on John D. Cook.
Why do medical tests always have error rates?
Most people implicitly assume medical tests are infallible. If they test positive for X, they assume they have X. Or if they test negative for X, they're confident they don't have X. Neither is necessarily true. Someone recently asked me why medical tests always have an error rate. It's a good question. A test is [...]The post Why do medical tests always have error rates? first appeared on John D. Cook.
Rényi’s parking constant
Imagine parallel parking is available along the shoulder of a road, but no parking spaces are marked. The first person to park picks a spot on the shoulder at random. Then another car also chooses a spot along the shoulder at random, with the constraint that the second car can't overlap the first. This process [...]The post Renyi's parking constant first appeared on John D. Cook.
Calculating when a planet will appear to move backwards
When we say that the planets in our solar system orbit the sun, not the earth, we mean that the motions of the planets is much simpler to describe from the vantage point of the sun. The sun is no more the center of the universe than the earth is. Describing the motion of the [...]The post Calculating when a planet will appear to move backwards first appeared on John D. Cook.
Do incremental improvements add, multiply, or something else?
Suppose you make an x% improvement followed by a y% improvement. Together do they make an (x + y)% improvement? Maybe. The business principle of kaizen, based on the Japanese for improvement, is based on the assumption that incremental improvements accumulate. But quantifying how improvements accumulate takes some care. Add or multiply? Two successive [...]The post Do incremental improvements add, multiply, or something else? first appeared on John D. Cook.
The Clausen function
I ran across the Clausen function the other day, and when I saw a plot of the function my first thought was that it looks sorta like a sawtooth wave. I wondered whether it also sounds like a sawtooth wave, and indeed it does. More on that shortly. The Clausen function can be defined in [...]The post The Clausen function first appeared on John D. Cook.
Limit of a doodle
Suppose you're in a boring meeting and you start doodling. You draw a circle, and then you draw a triangle on the outside of that circle. Next you draw a circle through the vertices of the triangle, and draw a square outside that. Then you draw a circle through the vertices of the square, and [...]The post Limit of a doodle first appeared on John D. Cook.
National Provider Identifier (NPI) and its checksum
Healthcare providers in the United States are required to have an ID number known as the NPI (National Provider Identifier). This is a 10-digit unique identifier which serves as the primary key in a publicly available database. You can use the NPI number to look up a provider's name, credentials, their practice location, etc. The [...]The post National Provider Identifier (NPI) and its checksum first appeared on John D. Cook.
Getting some (algorithmic) SAT-isfaction
How can you possibly solve a mission-critical problem with millions of variables-when the worst-case computational complexity of every known algorithm for that problem is exponential in the number of variables? SAT (Satisfiability) solvers have seen dramatic orders-of-magnitude performance gains for many problems through algorithmic improvements over the last couple of decades or so. The SAT [...]The post Getting some (algorithmic) SAT-isfaction first appeared on John D. Cook.
Computing Γ(z) for complex z with tables
In the previous post I mentioned that the general strategy for computing a mathematical function using tables is to first reduce the function argument to be within the range of the tabulated values, and then to use interpolation to compute the function at values that are not directly tabulated. The second step is always the [...]The post Computing (z) for complex z with tables first appeared on John D. Cook.
Calculating trig functions from tables
It takes some skill to use tables of mathematical functions; it's not quite as simple as it may seem. Although it's no longer necessary to use tables, it's interesting to look into the details of how it is done. For example, the Handbook of Mathematical Functions edited by Abramowitz and Stegun tabulates sines and cosines [...]The post Calculating trig functions from tables first appeared on John D. Cook.
Rapidly convergent series for ellipse perimeter
The previous post looked at two simple approximations for the perimeter of an ellipse. Approximations are necessary since the perimeter of an ellipse cannot be expressed as an elementary function of the axes. Kepler noted in 1609 that you could approximate the perimeter of an ellipse as the perimeter of a circle whose radius is [...]The post Rapidly convergent series for ellipse perimeter first appeared on John D. Cook.
Kepler’s ellipse perimeter approximations
In 1609, Kepler remarked that the perimeter of an ellipse with semiaxes a and b could be approximated either as P 2(ab) or P (a + b). In other words, you can approximate the perimeter of an ellipse by the circumference of a circle of radius r where r is either the geometric mean [...]The post Kepler's ellipse perimeter approximations first appeared on John D. Cook.
Power method and centrality
A few days ago I wrote about eigenvector centrality, a way of computing which nodes in a network are most important. Rather than simply looking for the most highly connected nodes, it looks for nodes that are highly connected to nodes that are highly connected. It's the idea behind Google's PageRank algorithm. Adjacency matrices One [...]The post Power method and centrality first appeared on John D. Cook.
The search for the perfect prompt
Anyone with more than casual experience with ChatGPT knows that prompt engineering is a thing. Minor or even trivial changes in a chatbot prompt can have significant effects, sometimes even dramatic ones, on the output [1]. For simple requests it may not make much difference, but for detailed requests it could matter a lot. Industry [...]The post The search for the perfect prompt first appeared on John D. Cook.
Eigenvector centrality
A basic question to ask about a network is which nodes are most important. A simple way of answering this question would be to say the most well-connected nodes, i.e. the nodes with the most edges. This approach is known as degree centrality. It's not a bad place to start. It's easy to understand and [...]The post Eigenvector centrality first appeared on John D. Cook.
Fitting a line without an intercept term
The other day I was looking at how many lumens LED lights put out per watt. I found some data on Wikipedia, and as you might expect the relation between watts and lumens is basically linear, though not quite. If you were to do a linear regression on the data you'd get a relation lumens [...]The post Fitting a line without an intercept term first appeared on John D. Cook.
Solutions to tan(x) = x
I read something recently that said in passing that the solutions to the equation tan x = x are the zeros of the Bessel function J3/2. That brought two questions to mind. First, where have I seen the equation tan x = x before? And second, why should its solutions be the roots of a [...]The post Solutions to tan(x) = x first appeared on John D. Cook.
Computing logarithms of complex numbers
The previous post showed how to compute logarithms using tables. It gives an example of calculating a logarithm to 15 figures precision using tables that only allow 4 figures of precision for inputs. Not only can you bootstrap tables to calculate logarithms of real numbers not given in the tables, you can also bootstrap a [...]The post Computing logarithms of complex numbers first appeared on John D. Cook.
Using a table of logarithms
My favorite quote from Richard Feynman is his remark that nearly everything is really interesting if you go into it deeply enough." This post will look at something that seems utterly trivial-looking up numbers in a table-and show that there's much more to it when you dig a little deeper. More than just looking up [...]The post Using a table of logarithms first appeared on John D. Cook.
12345678910...