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 2025-09-12 03:31
Kalman filters and functional programming
A few weeks ago I started a series of posts on various things you could do with a functional fold. In the first post I mentioned that the idea came from a paper by Brian Beckman on Kalman filters and folds: This post was inspired by a paper by Brian Beckman (in progress) that shows how […]
Formal methods let you explore the corners
I heard someone say the other day that the advantage of formal software validation methods is that they let you explore the corners, cases where intuition doesn’t naturally take you. This made me think of corners in the geometric sense. If you have a sphere in a box in high dimensions, nearly all the volume […]
The best way to develop software
The best way to develop software doesn’t exist. There’s only the best way that you know of, for a particular problem, with particular people, given their skills, experience, and constraints.
Literate programming: presenting code in human order
Presentation order People best understand computer programs in a different order than compilers do. This is a key idea of literate programming, and one that distinguishes literate programs from heavily commented programs. Traditional source code, no matter how heavily commented, is presented in the order dictated by the compiler. The computer is the primary audience. Literate programming is more humanistic in […]
Distribution of numbers in Pascal’s triangle
This post explores a sentence from the book Single Digits: Any number in Pascal’s triangle that is not in the outer two layers will appear at least three times, usually four. Pascal’s triangle contains the binomial coefficients C(n, r) where n ranges over non-negative numbers and r ranges from 0 to n. The outer layers are the elements with r equal to […]
Agile software development and homotopy
One of the things I learned from my tenure as a software project manager was that a project is more likely to succeed if there’s a way to get where you want to go continuously. You want to move a project from A to B gradually, keeping a working code base all along the way. At […]
Group projects
The best teams have people with complementary skills, but similar work ethic. Academic assignments are the opposite. There’s not much variation in skills, in part because students haven’t yet developed specialized skills, and in part because students are in the same class because they have similar interests. The biggest variation is likely to be work ethic. It’s […]
Fair division and the Thue-Morse sequence
Suppose two captains, A and B, are choosing people for their teams. To make things fair, the two captains alternate choices: A, B, A, B, etc. This is much better than simply letting A choose his team first and leaving B the dregs, but it still gives A a substantial advantage. If each captain picks the best remaining […]
Positive polynomials and squares
If a real polynomial in one variable is a sum of squares, it obviously cannot be negative. For example, the polynomial p(x) = (x2 – 3)2 + (x + 7)2 is obviously never negative for real values of x. What about the converse: If a real polynomial is never negative, is it a sum of […]
Sparsely populated zip codes
The dormitory I lived in as an undergraduate had its own five-digit zip code at one time. It was rumored to be the largest dorm in the US, or maybe the largest west of the Mississippi, or something like that. There were about 3,000 of us living there. Although the dorm had enough people to justify […]
Category theory and Koine Greek
When I was in college, I sat in on a communication workshop for Latin American preachers. This was unusual since I’m neither Latin American nor a preacher, but I’m glad I was there. I learned several things in that workshop that I’ve used ever since. For example, when you’re gesturing about something moving forward in time, move your […]
New Twitter account for functional programming and categories
I’m starting a new Twitter account @FunctorFact for functional programming and category theory. These two subjects have a lot of overlap, and some tweets will combine both, but many will be strictly about one or the other. So some content will be strictly about programming, some strictly about math, and some combining ideas from both.
Prime factors, phone numbers, and the normal distribution
Telephone numbers typically have around three distinct prime factors. The length of a phone number varies by country, but US a phone number is a 10 digit number, and 10-digit numbers are often divisible by three different prime numbers, give or take a couple. Assuming phone numbers are scattered among possible 10-digit numbers in a way that […]
Five lemma, ASCII art, and Unicode
A few days ago I wrote about creating ASCII art in Emacs using ditaa. Out of curiosity, I wanted to try making the Five Lemma diagram. [1] The examples in the ditaa site all have arrows between boxes, but you don’t have to have boxes. Here’s the ditaa source: A₀ ---> A₁ ---> A₂ ---> […]
Benford’s law, chi-square, and factorials
A while back I wrote about how the leading digits of factorials follow Benford’s law. That is, if you look at just the first digit of a sequence of factorials, they are not evenly distributed. Instead, 1’s are most popular, then 2’s, etc. Specifically, the proportion of factorials starting with n is roughly log10(1 + 1/n). […]
Hypothesis testing and number theory
This post uses a hypothesis test for proportions to look at a couple conjectures in number theory. It is similar to my earlier post on the chi-square test and prime remainders. You could read this as a post on statistics or a post on number theory, depending on which you’re less familiar with. Using statistical […]
Musical instrument acoustics posts
Four posts about musical instrument acoustics: Electric guitars Kettledrums Saxophones Leaf blowers
Category theory and micro-epiphanies
Once in a while something big suddenly makes sense. Far more often, things make sense a little at a time. I was talking with someone a few days ago, and we both said that we never had an epiphany when category theory suddenly made sense. Instead, we both said we had a sequence of micro-epiphanies. […]
ASCII art diagrams in Emacs org-mode
Yesterday I wrote about ASCII art diagrams and gave four reasons you might want to use this ancient approach to creating simple diagrams: It could be quicker than creating a graphical image . You can paste them into plain text documents like source code files. They can be produced programmatically. There is software to turn ASCII […]
ASCII art diagrams
“Technology is additive.” — Kevin Kelly Old technologies never die. Instead, their range of application shrinks. Or maybe it grows when conditions change. ASCII art, drawing pictures with fixed-width plain text characters, is no longer how many people want to produce diagrams. Just fire up Adobe Illustrator and you get incomparably more resolution of expression. […]
Interview with Chris Toomey of Upcase
The other day I spoke to Chris Toomey from thoughtbot. Chris runs Upcase, thoughtbot’s online platform for learning about Rails, test-driven development, clean code, and more. I was curious about his work with Ruby on Rails since I know little about that world. And at a little deeper level, I wanted to get his thoughts […]
Insertion sort as a fold
I’ve written several posts lately about various algorithms that can be expressed as functional folds: updating conjugate Bayesian models solving differential equations computing sample statistics These have all been numerical algorithms. Insertion sort is an example of a non-numerical algorithm that could be implemented as a fold. Insertion sort is not the fastest sorting algorithm. […]
Prime remainders too evenly distributed
First Brian Hayes wrote an excellent post about the remainders when primes are divided by other primes. Then I wrote a follow-on just focusing on the first part of his post. He mostly looked at pairs of primes, but I wanted to look in more detail at the first part of his post, simulating dice […]
Computing higher moments with a fold
Folds in functional programming are often introduced as a way to find the sum or product of items in a list. In this case the fold state has the same type as the list items. But more generally the fold state could have a different type, and this allows more interesting applications of folds. Previous […]
Chi-square goodness of fit test example with primes
Yesterday Brian Hayes wrote a post about the distribution of primes. He showed how you could take the remainder when primes are divided by 7 and produce something that looks like rolls of six-sided dice. Here we apply the chi-square goodness of fit test to show that the rolls are too evenly distributed to mimic […]
Grateful for failures
I’ve been thinking lately about different things I’ve tried that didn’t work out and how grateful I am that they did not. The first one that comes to mind is my academic career. If I’d been more successful with grants and publications as a postdoc, it would have been harder to decide to leave academia. […]
Ten spectral graph theory posts
Here are 10 blog posts I wrote earlier this year about spectral graph theory, studying graphs via the eigenvalues of matrices associated with the graphs. Measuring graph connectivity with eigenvalues Graph regularity and Laplacian eigenvalues Adding an edge increases eigenvalues Spectral coordinates in Python Bipartite graphs and the signless Lapacian Spectra of random graphs Can […]
ODE solver as a functional fold
One of the most widely used numerical algorithms for solving differential equation is the 4th order Runge-Kutta method. This post shows how the Runge-Kutta method can be written naturally as a fold over the set of points where the solution is needed. These points do not need to be evenly spaced. Given a differential equation […]
Functional folds and conjugate models
Bayesian calculations are intrinsically recursive: The posterior distribution from one step becomes the prior for the next step. With conjugate models, the prior and posterior belong to the same family of distributions. If a distribution from this family is determined by a fixed set of parameters, we only need to update these parameters at each step. This updating process is […]
Retronyms and Backronyms
A retronym is a new name created for an old thing, often made necessary by technological changes. For example, we have terms like “postal mail” or “snail mail” for what used to simply be “mail” because email has become the default. What was once called a “transmission” is now called a “manual transmission” since most […]
Flood control parks
The park in the photo above flooded. And that’s a good thing. It’s designed to flood so that homes don’t. It’s not really a park that flooded. It’s a flood control project that most of the time doubles as a park. Ordinarily the park has a lake, but a few days a year the park is […]
Kalman filters and bottom-up learning
Kalman filtering is a mixture of differential equations and statistics. Kalman filters are commonly used in tracking applications, such as tracking the location of a space probe or tracking the amount of charge left in a cell phone battery. Kalman filters provide a way to synthesize theoretical predictions and actual measurements, accounting for error in […]
Cepstral alanysis vocabulary
An earlier post defined cepstrum and quefrency. This post explains some of the other quirky terms introduced in the same paper by Bogert, Healy, and Tukey. (Given Tukey’s delight in coining words, we can assume he was the member of the trio responsible for the new terms.) The paper [1] explains why the new twists on […]
Selecting clients
One of the themes in David Ogilvy’s memoir Confessions of an Advertising Man is the importance of selecting good clients. For example, he advises “never take associations as clients” because they have “too many masters, too many objectives, too little money.” He also recommends not taking on clients that are so large that you would lose your independence […]
How about one good one?
I’m no fan of tobacco companies or their advertising tactics, but I liked the following story. When the head of a mammoth [advertising] agency solicited the Camel Cigarette account, he promised to assign thirty copywriters to it, but the canny head of R. J. Reynolds replied, “How about one good one?” Then he gave his account to […]
Cepstrum, quefrency, and pitch
John Tukey coined many terms that have passed into common use, such as bit (a shortening of binary digit) and software. Other terms he coined are well known within their niche: boxplot, ANOVA, rootogram, etc. Some of his terms, such as jackknife and vacuum cleaner, were not new words per se but common words he […]
Bring out your equations!
Nice discussion from Fundamentals of Kalman Filtering: A Practical Approach by Paul Zarchan and Howard Musoff: Often the hardest part in Kalman filtering is the subject that no one talks about—setting up the problem. This is analogous to the quote from the recent engineering graduate who, upon arriving in industry, enthusiastically says, “Here I am, […]
Top tweets
I had a couple tweets this week that were fairly popular. The first was a pun on the musical Hamilton and the Hamiltonian from physics. The former is about Alexander Hamilton (1755–1804) and the latter is named after William Rowan Hamilton (1805–1865). Hamiltonian: The new Broadway hit about the sum of potential and kinetic energy. pic.twitter.com/PCJk3imDsq […]
Tonal prominence in a leaf blower
This afternoon I was working on a project involving tonal prominence. I stepped away from the computer to think and was interrupted by the sound of a leaf blower. I was annoyed for a second, then I thought “Hey, a leaf blower!” and went out to record it. A leaf blower is a great example of […]
Loudness and sharpness
This post looks at loudness and sharpness, two important psychoacoustic metrics. Because they have to do with human perception, these factors are by definition subjective. And yet they’re not entirely subjective. People tend to agree on when, for example, one sound is twice as loud as another, or when one sound is sharper than another. Loudness Loudness […]
Electric guitar distortion
The other day I asked on Google+ if someone could make an audio clip for me and Dave Jacoby graciously volunteered. I wanted a simple chord on an electric guitar played with varying levels of distortion. Dave describes the process of making the recording as Fender Telecaster -> EHX LPB clean boost -> Washburn Soloist […]
Demystifying artificial intelligence
Computers do what we tell them to do. Period. Any talk of computers doing things they weren’t programmed to do is only a way of speaking. It’s a convenient shorthand when used properly, misleading mysticism when used improperly. When you write a program print(24*7) you could say that the computer isn’t programmed to print the number […]
Optimistic about humans in aggregate
Russ Roberts from his most recent podcast: I’m a very optimistic person, and I have a lot of faith in the human enterprise writ large—not so much in any one human. I have very little faith in any one human, which is why I’m suspicious of experts and power that is centralized.
Converting between Hz, Barks, and music notation
I’ve written before about how to convert between frequency and pitch and scientific pitch notation. I’ve also written about the Bark scale. Here’s a little online calculator to convert between Hz, Bark, and music notation. You can enter one of the three and it will compute the other two.
Spectral flatness
White noise has a flat power spectrum. So a reasonable way to measure how close a sound is to being pure noise is to measure how flat its spectrum is. Spectral flatness is defined as the ratio of the geometric mean to the arithmetic mean of a power spectrum. The arithmetic mean of a sequence […]
Family tree numbering
When you draw a tree of your ancestors, things quickly get out of hand. There are twice as many nodes each time you go back a generation, and so the size of paper you need grows exponentially. Things also get messy because typically you know much more about some lines than others. If you know […]
The acoustics of kettledrums
Kettledrums (a.k.a. tympani) produce a definite pitch, but in theory they should not. At least the simplest mathematical model of a kettledrum would not have a definite pitch. Of course there are more accurate theories that align with reality. Unlike many things that work in theory but not in practice, kettledrums work in practice but not in theory. […]
How to create Green noise in Python
This is a follow-on to my previous post on green noise. Here we create green noise with Python by passing white noise through a Butterworth filter. Green noise is in the middle of the audible spectrum (on the Bark scale), just where our hearing is most sensitive, analogous to the green light, the frequency where […]
Green noise and Barks
Colors of noise In a previous post I explained the rationale behind using names of colors to refer to different kinds of noise. The basis is an analogy between the spectra of sounds and the spectra of light. Red noise is biased toward the low end of the audio spectrum just as red light is […]
Consecutive pair magic square
The following magic square has a couple unusual properties. For one, numbers appear in consecutive pairs. Also, you can connect the numbers 1 through 32 in a continuous path. I found this in Before Sudoku. The authors attribute it to William Mannke, “A Magic Square.” Journal of Recreational Mathematics. 1 (3) page 139, July 1968. […]
...51525354555657585960