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 03:46
Mentally approximating factorials
Suppose you'd like to have a very rough idea how large n! is for, say, n less than 100. If you're familiar with such things, your Pavlovian response to factorial" and approximation" is Stirling's approximation. Although Stirling's approximation is extremely useful-I probably use it every few weeks-it is not conducive to mental calculation. The cut [...]The post Mentally approximating factorials first appeared on John D. Cook.
Leading digits of primes
How are the first digits of primes distributed? Do some digits appear as first digits of primes more often that others? How should we even frame the problem? There are an infinite number of primes that begin with each digit, so the cardinalities of the sets of primes beginning with each digit are the same. [...]The post Leading digits of primes first appeared on John D. Cook.
Matching delimiters and chiastic patterns
When I first started programming I'd occasionally get an error because a delimiter wasn't matched. Maybe I had a { without a matching }, for example. Or if I were writing Pascal, which I did back in the day, I might have had a BEGIN statement without a corresponding END statement. At some point I [...]The post Matching delimiters and chiastic patterns first appeared on John D. Cook.
Equation of an ellipse or hyperbola through five points
Yesterday I wrote about the equation of a circle through three points. This post will be similar, looking at the equation of an ellipse or hyperbola through five points. As with the earlier post, we can write down an elegant equation right away. Making the equation practical will take more work. The equation of a [...]The post Equation of an ellipse or hyperbola through five points first appeared on John D. Cook.
A parabola, a triangle, and a circle
Let P be a parabola. Draw tangents to P at three different points. These three lines intersect to form a triangle. Theorem: The circumcircle of this triangle passes through the focus of P. [1] In the image above, the dashed lines are tangents and the black dot is the focus of the parabola. (See this [...]The post A parabola, a triangle, and a circle first appeared on John D. Cook.
Equation of a circle through three points
A few months ago I wrote about several equations that come up in geometric calculations that all have the form of a determinant equal to 0, where one column of the determinant is all 1s. The equation of a circle through three points (x1, y1), (x2, y2), and (x3, y3) has this form: This is [...]The post Equation of a circle through three points first appeared on John D. Cook.
Set of orbits with the same average distance to sun
Suppose a planet is in an elliptical orbit around the sun with semimajor axis a and semiminor axis b. Then the average distance of the planet to the sun over time equals a(1 + e^2/2) where the eccentricity e satisfies e^2 = 1 - b^2/a^2. You can find a proof of this statement in [1]. [...]The post Set of orbits with the same average distance to sun first appeared on John D. Cook.
Pushing numerical integration software to its limits
The previous post discussed the functions as test cases for plotting. This post will look at using the same functions as test cases for integration. As you can see from the plot of f30(x) below, the function is continuous, but the derivative of the function has a lot of discontinuities. The integrals of Steinerberger's [...]The post Pushing numerical integration software to its limits first appeared on John D. Cook.
Plotting a function with a lot of local minima
Stefan Steinerberger defines an amusing sequence of functions" in [1] by Here's a plot of f30(x): As you can see, fn(x) has a lot of local minima, and the number of local minima increases rapidly with n. Here's a naive attempt to produce the plot above using Python. from numpy import sin, pi, linspace import [...]The post Plotting a function with a lot of local minima first appeared on John D. Cook.
Collecting a large number of coupons
This post is an addendum to the recent post Reviewing a thousand things. We're going to look again at the coupon collector problem, randomly sampling a set of N things with replacement until we've collected one of everything. As noted before, for largeNthe expected number of draws before you've seen everything at least once is [...]The post Collecting a large number of coupons first appeared on John D. Cook.
Trig crossings and root of gold
Here's a curious fact. The graphs of cotangent and secant cross at the same height as the graphs of tangent and cosecant, and this common height is the square root of the golden ratio . It's also the case that the graphs of hyperbolic cosecant and hyperbolic cosine, and the graphs of hyperbolic sine and [...]The post Trig crossings and root of gold first appeared on John D. Cook.
Beta-binomial with given mean and variance
The previous post looked at an application of the beta-binomial distribution. The probability mass function for a beta-binomial with parameters n, a, and b is given by The mean μ and the variance σ² are given by Solving for a and b to meet a specified mean and variance appears at first to require solving […]The post Beta-binomial with given mean and variance first appeared on John D. Cook.
Babies and the beta-binomial distribution
About half of children are boys and half are girls, but that doesn’t mean that every couple is equally likely to have a boy or a girl each time they conceive a child. And evidence suggests that indeed the probability of conceiving a girl varies per couple. I will simplify things for this post and […]The post Babies and the beta-binomial distribution first appeared on John D. Cook.
Similar triangles and complex numbers
Suppose the vertices of two triangles are given by complex numbers a, b, c and x, y, z. The two triangles are similar if This can be found in G. H. Hardy’s classic A Course of Pure Mathematics. It’s on page 93 in the 10th edition. Corollary The theorem above generalizes a result from an […]The post Similar triangles and complex numbers first appeared on John D. Cook.
Powers of a 2×2 matrix in closed form
Here’s something I found surprising: the powers of a 2×2 matrix have a fairly simple closed form. Also, the derivation is only one page [1]. LetA be a 2×2 matrix with eigenvalues α and β. (3Blue1Brown made a nice jingle for finding the eigenvalues of a 2×2 matrix.) If α = β then the nth […]The post Powers of a 2×2 matrix in closed form first appeared on John D. Cook.
Instant classic
“Instant classic” is, of course, an oxymoron. A classic is something that has passed the test of time, and by definition that cannot happen instantly. But how long should the test of time last? In his book Love What Lasts, Joshua Gibbs argues that 100 years after the death of the artist is about the […]The post Instant classic first appeared on John D. Cook.
Occupancy problem distribution
Suppose you have a random number generator that returns numbers between 1 and N. The birthday problem asks how many random numbers would you have to output before there’s a 50-50 chance that you’ll repeat a number. The coupon collector problem asks how many numbers you expect to generate before you’ve seen all N numbers […]The post Occupancy problem distribution first appeared on John D. Cook.
Hypergeometric distribution symmetry
One of these days I’d like to read Feller’s probability book slowly. He often says clever things in passing that are easy to miss. Here’s an example from Feller [1] that I overlooked until I saw it cited elsewhere. Suppose an urn contains n marbles, n1 red and n2 black. When r marbles are drawn […]The post Hypergeometric distribution symmetry first appeared on John D. Cook.
AM over GM
Suppose you take the arithmetic mean and the geometric mean of the first n integers. The ratio of these two means converges to e/2 as n grows [1]. In symbols, Now suppose we wanted to visualize the convergence by plotting the expression on the left side for a sequence of ns. First let’s let n […]The post AM over GM first appeared on John D. Cook.
Category theory without categories
I was bewildered by my first exposure to category theory. My first semester in graduate school I had a textbook with definitions like “A gadget is an object G such that whenever you have this unfamiliar constellation of dots and arrows, you’re allowed to draw another arrow from here to there.” What? Why?! I revisited […]The post Category theory without categories first appeared on John D. Cook.
Contraharmonic mean
I’ve mentioned the harmonic mean multiple times here, most recently last week. The harmonic mean pops up in many contexts. The contraharmonic mean is a variation on the harmonic mean that comes up occasionally, though not as often as its better known sibling. Definition The contraharmonic mean of two positive numbers a and b is […]The post Contraharmonic mean first appeared on John D. Cook.
Bibliography histogram
I recently noticed something in a book I’ve had for five years: the bibliography section ends with a histogram of publication dates for references. I’ve used the book over the last few years, but maybe I haven’t needed to look at the bibliography before. This is taken from Bernstein’s Matrix Mathematics. I wrote a review […]The post Bibliography histogram first appeared on John D. Cook.
Cofactors, determinants, and adjugates
Let A be an n × n matrix over a field F. The cofactor of an element Aij is the matrix formed by removing the ith row and jth column, denoted A[i, j]. This terminology is less than ideal. The matrix just described is called the cofactor of Aij, but it would more accurately be […]The post Cofactors, determinants, and adjugates first appeared on John D. Cook.
Arithmetic-harmonic mean
I’ve written several times about the arithmetic-geometric mean and variations. Take the arithmetic and geometric mean of two positive numbers a and b. Then take the arithmetic and geometric of the means from the previous step. Repeat ad infinitum and the result converges to a limit. This limit is called the arthmetic-geometric mean or AGM. […]The post Arithmetic-harmonic mean first appeared on John D. Cook.
Circulant matrices commute
A few days ago I wrote that circulant matrices all have the same eigenvectors. This post will show that it follows that circulant matrices commute with each other. Recall that a circulant matrix is a square matrix in which the rows are cyclic permutations of each other. If we number the rows from 0, then […]The post Circulant matrices commute first appeared on John D. Cook.
Relativity, complex numbers, and gyrovectors
The previous post discussed an unusual algebraic structure on the real interval (-1, 1) inspired by (and applied to) special relativity. We defined an addition operator ⊕ by How might we extend this from the interval (-1, 1) to the unit disk in the complex plane? The definition won’t transfer over unmodified because it does […]The post Relativity, complex numbers, and gyrovectors first appeared on John D. Cook.
Packing versus unpacking
I usually think of an instructor as someone who unpacks things, such as unpacking the meaning of an obscure word or explaining a difficult concept. Last night I was trying to read some unbearably dry medical/legal material and thought about how an instructor might also pack things, wrapping dry material in some sort of story […]The post Packing versus unpacking first appeared on John D. Cook.
How faithful can a map be?
It’s well known that you cannot map a sphere onto the plane without distortion. You can’t map the entire sphere to the plane at all because a sphere and a plane are not topologically equivalent. But even if you want to map a relatively small portion of globe to paper, say France, with about 0.1% […]The post How faithful can a map be? first appeared on John D. Cook.
Recognizing three-digit primes
If a three-digit number looks like it might be prime, there’s about a 2 in 3 chance that it is. To be more precise about what it means for a number to “look like a prime,” let’s say that a number is obviously composite if it is divisible by 2, 3, 5, or 11. Then […]The post Recognizing three-digit primes first appeared on John D. Cook.
Expected distance between points in a cube
Suppose you randomly sample points from a unit cube. How far apart are pairs of points on average? My intuition would say that the expected distance either has a simple closed form or no closed form at all. To my surprise, the result is somewhere in between: a complicated closed form. Computing the expected value […]The post Expected distance between points in a cube first appeared on John D. Cook.
Sine of factorial degrees
I was looking back at a post about the Soviet license plate game and was reminded of the amusing identity sin (n!)° = 0 for n ≥ 6. Would it be possible to find sin (n!)° in closed form for all positive integers n? For this post I’ll make an exception to my usual rule […]The post Sine of factorial degrees first appeared on John D. Cook.
LTI operators commute
Here’s a simple but surprising theorem from digital signal processing: linear, time-invariant (LTI) operators commute. The order in which you apply LTI operators does not matter. Linear in DSP means just you’d expect from seeing linear defined anywhere else: An operator L is linear if given any two signals x1 and x2, and any two […]The post LTI operators commute first appeared on John D. Cook.
Approximate monthly loan payments
This post presents a simple method of estimating monthly payments on a loan. According to [1] this is a traditional Persian method and still commonly used in Iran. A monthly payment amount is (principal + interest)/months but the total amount of interest over the course of a loan is complicated to compute. Initially you owe […]The post Approximate monthly loan payments first appeared on John D. Cook.
How to memorize Unicode codepoints
At the end of each month I write a newsletter highlighting the most popular posts of that month. When I looked back at my traffic stats to write this month’s newsletter I noticed that a post I wrote last year about how to memorize the ASCII table continues to be popular. This post is a […]The post How to memorize Unicode codepoints first appeared on John D. Cook.
Golden integration
Let φ be the golden ratio. The fractional parts of nφ bounce around in the unit interval in a sort of random way. Technically, the sequence is quasi-random. Quasi-random sequences are like random sequences but better in the sense that they explore a space more efficiently than random sequences. For this reason, Monte Carlo integration […]The post Golden integration first appeared on John D. Cook.
Moving between differential and integral equations
My years in graduate school instilled a Pavlovian response to PDEs: multiply by a test function and integrate by parts. This turns a differential equation into an integral equation [1]. I’ve been reading a book [2] on integral equations right now, and it includes several well-known techniques for turning certain kinds of integral equations into […]The post Moving between differential and integral equations first appeared on John D. Cook.
Symbols for angles
I was looking around in the Unicode block for miscellaneous symbols, U+2600, after I needed to look something up, and noticed there are four astrological symbols for angles: ⚹, ⚺, ⚻, and ⚼. These symbols are mysterious at first glance but all make sense in hindsight as I’ll explain below. Sextile The first symbol, ⚹, […]The post Symbols for angles first appeared on John D. Cook.
Overpowered proof that π is transcendental
There is no polynomial with rational coefficients that evaluates to 0 at π. That is, π is a transcendental number, not an algebraic number. This post will prove this fact as a corollary of a more advanced theorem. There are proof that are more elementary and direct, but the proof given here is elegant. A […]The post Overpowered proof that π is transcendental first appeared on John D. Cook.
Beta approximation to binomial
It is well-known that you can approximate a binomial distribution with a normal distribution. Of course there are a few provisos … It is also well-known that you can approximate a beta distribution with a normal distribution as well. This means you could directly approximate a binomial distribution with a beta distribution. This is a […]The post Beta approximation to binomial first appeared on John D. Cook.
Query, then deidentify
Suppose you have a database of personally identifiable information (PII) and you want to allow someone else to query the data while protecting the privacy of the individuals represented by the data. There are two approaches: Deidentify, then query Query, then deidentify The first approach is to do whatever is necessary to deidentify the data—remove […]The post Query, then deidentify first appeared on John D. Cook.
Can you have confidence in a confidence interval?
“The only use I know for a confidence interval is to have confidence in it.” — L. J. Savage Can you have confidence in a confidence interval? In practice, yes. In theory, no. If you have a 95% confidence interval for a parameter θ, can you be 95% sure that θ is in that interval? […]The post Can you have confidence in a confidence interval? first appeared on John D. Cook.
The essence of chaos
Linear systems can show sensitive dependence on initial conditions, but they cannot be chaotic. Only nonlinear systems can be chaotic. George Datseris and Ulrich Parlitz explain this well in their book Nonlinear Dynamics: … Sensitive dependence is not sufficient for a definition of chaos. … the state space is first stretched and then folded within […]The post The essence of chaos first appeared on John D. Cook.
Luhn checksum algorithm
After writing the previous post on credit card numbers, I intended to link to a previous post that discussed credit card check sums. But I couldn’t find such a post. I’ve written about other kinds of checksums, such as the checksum scheme used in Vehicle Identification Numbers, but apparently I haven’t written about credit card […]The post Luhn checksum algorithm first appeared on John D. Cook.
What can you learn from a credit card number?
The first 4 to 6 digits of a credit card number are the bank identification number or BIN. The information needed to decode a BIN is publicly available, with some effort, and so anyone could tell from a credit card number what institution issued it, what bank it draws on, whether its a personal or […]The post What can you learn from a credit card number? first appeared on John D. Cook.
Tradeoff between alphabet size and word size
Literal alphabets Natural language alphabets are all within an order of magnitude of the size of the Roman alphabet. The Hebrew alphabet has a few less letters and Russian has a few more. The smallest alphabet I’m aware of is Hawaiian with 13 letters. Syllabaries are larger than alphabets, but not an order of magnitude […]The post Tradeoff between alphabet size and word size first appeared on John D. Cook.
How Albrecht Dürer drew an 11-sided figure
You cannot exactly construct an 11-sided regular polygon (called a hendecagon or an undecagon) using only a straight edge and compass. Gauss fully classified which regular n-gons can be constructed, and this isn’t one of them [1]. However, Albrecht Dürer [2] came up with a good approximate construction for a hendecagon. To construct an eleven-sided […]The post How Albrecht Dürer drew an 11-sided figure first appeared on John D. Cook.
Gold, silver, and bronze ratios
The previous post showed that if you inscribe a hexagon and a decagon in the same circle, the ratio of the sides of the two polygons is the golden ratio. After writing the post I wondered whether you could construct the silver ratio or bronze ratio in an analogous way. Metallic ratios To back up […]The post Gold, silver, and bronze ratios first appeared on John D. Cook.
A pentagon, hexagon, and decagon walk into a bar …
The new book A Panoply of Polygons cites a theorem Euclid (Proposition XIII.10) saying If a regular pentagon, a regular hexagon, and a regular decagon are inscribed in congruent circles, then their side lengths form a right triangle. This isn’t exactly what Euclid said, but it’s an easy deduction from what he did say. Here’s […]The post A pentagon, hexagon, and decagon walk into a bar … first appeared on John D. Cook.
A new trig identity
This evening I ran across a trig identity I hadn’t seen before. I doubt it’s new to the world, but it’s new to me. Let A, B, and C be the angles of an arbitrary triangle. Then sin² A + sin² B + sin² C = 2 + 2 cos A cos B cos C. […]The post A new trig identity first appeared on John D. Cook.
Piranhas and prime factors
The piranha problem says an event cannot be highly correlated with a large number of independent predictors. If you have a lot of strong predictors, they must predict each other, analogous to having too many piranhas in a small body of water: they start to eat each other. The piranha problem is subtle. It can […]The post Piranhas and prime factors first appeared on John D. Cook.
...6789101112131415...