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 01:46
Simulating seashells
In 1838, Rev. Henry Moseley discovered that a large number of mollusk shells and other shells can be described using three parameters: k, T, and D. First imagine a thin wire running through the coil of the shell. In cylindrical coordinates, this wire follows the parameterization r = ekθ z = Tt If T = 0 this is a […]
Recreating the Vertigo poster
In his new book The Perfect Shape, Øyvind Hammer shows how to create a graph something like the poster for Alfred Hitchcock’s movie Vertigo. Hammer’s code uses a statistical language called Past that I’d never heard of. Here’s my interpretation of his code using Python. import matplotlib.pyplot as plt from numpy import arange, sin, cos, […]
Inverse Fibonacci numbers
As with the previous post, this post is a spinoff of a blog post by Brian Hayes. He considers the problem of determining whether a number n is a Fibonacci number and links to a paper by Gessel that gives a very simple solution: A positive integer n is a Fibonacci number if and only if either 5n2 – […]
Approximate inverse of the gamma function
The other day I ran across a blog post by Brian Hayes that linked to an article by David Cantrell on how to compute the inverse of the gamma function. Cantrell gives an approximation in terms of the Lambert W function. In this post we’ll write a little Python code to kick the tires on […]
How efficient is Morse code?
Morse code was designed so that the most frequently used letters have the shortest codes. In general, code length increases as frequency decreases. How efficient is Morse code? We’ll compare letter frequencies based on Google’s research with the length of each code, and make the standard assumption that a dash is three times as long as a dot. […]
Tidying up trivial details
The following quote gives a good description of the value of abstract mathematics. The quote speaks specifically of “universal algebra,” but consistent with the spirit of the quote you could generalize it to other areas of mathematics, especially areas such as category theory. Universal algebra is the study of features common to familiar algebraic systems […]
Measuring graph robustness
There are a couple ways to measure how well a graph remains connected when nodes are removed. One ways is to consider nodes dropping out randomly. Another way, the one we look at here, assumes an adversary is trying to remove the most well-connected nodes. This approach was defined by Schneider et al [1]. It […]
Data-driven charity
In this post I interview GiveDirectly co-founder Paul Niehaus about charitable direct cash transfers and their empirical approach to charity. JC: Can you start off by telling us a little bit about Give Directly, and what you do? PN: GiveDirectly is the first nonprofit that lets individual donors like you and me send money directly to […]
Big data and the law
Excerpt from the new book Big Data of Complex Networks: Big Data and data protection law provide for a number of mutual conflicts: from the perspective of Big Data analytics, a strict application of data protection law as we know it today would set an immediate end to most Big Data applications. From the perspective of […]
Particle filter and unscented Kalman filter in a nutshell
Suppose you have a linear dynamic system. That is, the function that predicts the next state from the current state to the next is linear. Suppose also that the states in your system are not known precisely but have some uncertainty modeled by a (multivariate) normal distribution. Then the uncertainty in the state at the […]
Heavy-tailed random matrices
Suppose you fill the components of a matrix with random values. How are the eigenvalues distributed? We limit our attention to large, symmetric matrices. We fill the entries of the matrix on the diagonal and above the diagonal with random elements, then fill in the elements below the diagonal by symmetry. If we choose our […]
Simplify integration with complex variables
Last night I was helping my daughter with her calculus homework. One of the problems was the following integral: This is an interesting problem for two reasons. First, it illustrates a clever variation on integration by parts; that’s why it was assigned. But it can also be computed using complex variables. As is often the […]
Sticky cards
Suppose you shuffle a deck of cards. How likely is it that there are two cards that were next to each other before the shuffle are still next to each other after the shuffle? It depends on how well you shuffle the cards. If you do what’s called a “faro shuffle” then the probability of […]
Category Theory and Facebook
From Drew Armstrong’s notes on adjoint functors: Once upon a time, my opinion of category theory was the same as my opinion of Facebook: if I ignore it for long enough, hopefully it will go away. It is now my educated opinion that category theory will not go away, and in fact the language of […]
Infinite primes via Fibonacci numbers
A well-known result about Fibonacci numbers says gcd(Fm, Fn) = Fgcd(m, n) In words, the greatest common divisor of the mth and nth Fibonacci numbers is the gth Fibonacci number where g is the greatest common divisor of m and n. You can find a proof here. M. Wunderlich used this identity to create a short, clever proof that there are infinitely many […]
Safe primes, Sylow theorems, and Cryptography
A logarithm is the inverse of an exponential, and so we can generalize the idea of a logarithm wherever we can generalize the idea of an exponential. In particular, we can raise elements to exponents in a discrete group, and that leads to the definition of a discrete logarithm. Diffie-Hellman public key cryptography is based […]
Automated theorem proving
When I first heard of automated theorem proving, I imagined computers being programmed to search for mathematical theorems interesting to a wide audience. Maybe that’s what a few of the pioneers in the area had in mind too, but that’s not how things developed. The biggest uses for automated theorem proving have been highly specialized […]
Probability of secure hash collisions
A hash function maps arbitrarily long input strings to fixed-length outputs. For example, SHA-256 maps its input to a string of 256 bits. A cryptographically secure hash function h is a one-way function, i.e. given a message m it’s easy to compute h(m) but it’s not practical to go the other way, to learn anything about m from h(m). Secure hash functions are useful for […]
Three proofs that 2017 is prime
Aaron Meurer asked on Twitter whether there’s a proof that 2017 is prime that would fit into 140 characters. My first reply was this: sqrt(2017) < 45. 2017 not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, or 43. Ergo prime. I’m not sure that’s what he had […]
Monthly highlights
If you enjoy reading the articles here, you might like a monthly review of the most popular posts. I send out a newsletter at the end of each month. I’ve sent out around 20 so far. They all have two parts: a review of the most popular posts of the month, and a few words […]
Cover time of a graph: cliques, chains, and lollipops
Cover time The cover time of a graph is the expected time it takes a simple random walk on the graph to visit every node. A simple random walk starts at some node, then at each step chooses with equal probability one of the adjacent nodes. The cover time is defined to be the maximum […]
Changing names
I’ve just started reading Laurus, an English translation of a contemporary Russian novel. The book opens with this paragraph. He had four names at various times. A person’s life is heterogeneous, so this could be seen as an advantage. Life’s parts sometimes have little in common, so little that it might appear that various people […]
Bernoulli numbers, Riemann zeta, and strange sums
In the previous post, we looked at sums of the first n consecutive powers, i.e. sums of the form where p was a positive integer. Here we look at what happens when we let p be a negative integer and we let n go to infinity. We’ll learn more about Bernoulli numbers and we’ll see what […]
Sums of consecutive powers
There’s a well-known formula for the sum of the first n positive integers: 1 + 2 + 3 + … + n = n(n + 1) / 2 There’s also a formula for the sum of the first n squares 12 + 22 + 32 + … + n2 = n(n + 1)(2n + 1) / 6 […]
Rapidly mixing random walks on graphs
Random walks mix faster on some graphs than on others. Rapid mixing is one of the ways to characterize expander graphs. By rapid mixing we mean that a random walk approaches its limiting (stationary) probability distribution quickly relative to random walks on other graphs. Here’s a graph that supports rapid mixing. Pick a prime p and label nodes 0, 1, 2, 3, […]
Top three posts of 2016
These were the most popular posts this year: Random number generator seed mistakes Unusual proof that there are infinitely many primes Literate programming: presenting code in human order
Branch cuts and Common Lisp
“Nearly everything is really interesting if you go into it deeply enough.” — Richard Feynman If you thumb through Guy Steele’s book Common Lisp: The Language, 2nd Edition, you might be surprised how much space is devoted to defining familiar functions: square root, log, arcsine, etc. He gives some history of how these functions were […]
Subjectivity in statistics
Andrew Gelman on subjectivity in statistics: Bayesian methods are often characterized as “subjective” because the user must choose a prior distribution, that is, a mathematical expression of prior information. The prior distribution requires information and user input, that’s for sure, but I don’t see this as being any more “subjective” than other aspects of a […]
Most mathematical problem statement
Every so often college students will ask me for advice regarding going into applied math. I’ll tell them the first step in an application, and often the hardest step, is formulating a problem, not solving it. People don’t approach you with mathematical problems per se but problems that can be turned into mathematical problems. Nobody is going […]
An integral with a couple lessons
If you present calculus students with a definite integral, their Pavlovian response is “Take the anti-derivative, evaluate it at the limits, and subtract.” They think that’s what it means. But it’s not what a definite integral means. It’s how you (usually) calculate its value. This is not a pedantic fine point but a practically important distinction. It pays […]
How a couple failed auditions worked out well
When I was in high school, one year I made the Region choir. I had no intention of competing at the next level, Area, because I didn’t think I stood a chance of going all the way to State, and because the music was really hard: Stravinsky’s Symphony of Psalms. My choir director persuaded me […]
New iPhone app MathFeed for math news
Francis Su has created an iPhone app MathFeed that gives a stream of new math content: blog posts, book reviews, popular journal articles, and tweets. You can also get the same content via Twitter. Check it out!
Setting up Emacs shell on a Mac
Here are a few things I’ve had to figure out in the process of setting up Emacs on a Mac, in particular with getting shell-mode to work as I’d like. Maybe this will save someone else some time if they want to do the same. I’ve used a Mac occasionally since the days of the […]
Some frequently asked questions
I don’t have an FAQ page per se, but I’ve written a few blog posts where I answer some questions, and here I’ll answer a few more. Should I get a PhD? See my answer here and take a look at some of the other answers on the same site. Do you have any advice for people […]
Longhorn tribute to fallen Aggies
For many years, rivals University of Texas and Texas A&M University played each other in football on Thanksgiving. In 1999, the game fell one week after the collapse of the Aggie Bonfire killed 12 A&M students and injured 27. The University of Texas band’s half time show that year was a beautiful tribute to the fallen A&M students.
A different kind of network book
Yesterday I got a review copy of The Power of Networks. There’s some math inside, but not much, and what’s there is elementary. I’d say it’s not a book about networks per se but a collection of topics associated with networks: cell phone protocols, search engines, auctions, recommendation engines, etc. It would be a good […]
Hard work
The pinned tweet on my Twitter account at the moment says “Productivity tip: work hard.” It’s gotten a lot of positive feedback, so I assume it has resonated with a few people. Productivity tip: Work hard. — John D. Cook (@JohnDCook) October 8, 2015 I don’t know how people take it, but here’s what I […]
Ultra-reliable software
From a NASA page advocating formal methods: We are very good at building complex software systems that work 95% of the time. But we do not know how to build complex software systems that are ultra-reliably safe (i.e. P_f < 10^-7/hour). Emphasis added. Developing medium-reliability and high-reliability software are almost entirely different professions. Using typical […]
Technological allegiances
I used to wonder why people “convert” from one technology to another. For example, someone might convert from Windows to Linux and put a penguin sticker on their car. Or they might move from Java to Ruby and feel obligated to talk about how terrible Java is. They don’t add a new technology, they switch from […]
Truncated exponential series inequality
Define Tn to be the Taylor series for exp(x) truncated after n terms: How does this function compare to its limit, exp(x)? We might want to know because it’s often useful to have polynomial upper or lower bounds on exp(x). For x > 0 it’s clear that exp(x) is larger than Tn(x) since the discarded terms […]
Speed and correctness
Comment from Paul Phillips on making things easy to understand: It’s always been “We can’t do it that way. It would be too slow.” You know what’s slow? Spending all day trying to figure out why it doesn’t work. That’s slow. That’s the slowest thing I know.
Random squares
In geometry, you’d say that if a square has side x, then it has area x2. In calculus, you’d say more. First you’d say that if a square has side near x, then it has area near x2. That is, area is a continuous function of the length of a side. As the length of the side […]
Normal hazard continued fraction
The hazard function of a probability distribution is the instantaneous probability density of an event given that it hasn’t happened yet. This works out to be the ratio of the PDF (probability density function) to the CCDF (complementary cumulative density function). For the standard normal distribution, the hazard function is and has a surprisingly simple […]
A short, unusual proof that there are infinitely many primes
Sam Northshield [1] came up with the following clever proof that there are infinitely many primes. Suppose there are only finitely many primes and let P be their product. Then The original publication gives the calculation above with no explanation. Here’s a little commentary to explain the calculation. Since prime numbers are greater than 1, sin(π/p) is […]
A curious property of catenaries
Suppose you have a flat line f(x) = k and an interval [a, b]. Then the area under the line and over the interval is k times the length of the segment of the line. Surprisingly, the same is true for a catenary with scale k. With the flat line, the length of the segment of the graph is […]
Natural growth
Interesting passage from Small is Beautiful: Economics as if People Mattered by E. F. Schumacher: Nature always, so to speak, knows where and when to stop. There is a measure in all natural things—in their size, speed, or violence. As a result, the system of nature, of which man is a part, tends to be […]
When does a function equal its Taylor series?
Taylor’s theorem says When does the thing on the left equal the thing on the right? A few things could go wrong: Maybe not all the terms on the right side exist, i.e. the function f might not be infinitely differentiable. Maybe f is infinitely differentiable but the series diverges. Maybe f is infinitely differentiable but the […]
Valuing results and information
Chris Wiggins gave an excellent talk at Rice this afternoon on data science at the New York Times. In the Q&A afterward, someone asked how you would set up a machine learning algorithm where you’re trying to optimize for outcomes and for information. Here’s how I’ve approached this dilemma in the past. Information and outcomes are not […]
Computing discrete logarithms with baby-step giant-step algorithm
At first “discrete logarithm” sounds like a contradiction in terms. Logarithms aren’t discrete, not as we usually think of them. But you can define and compute logarithms in modular arithmetic. What is a logarithm? It’s the solution to an exponential equation. For example, the logarithm base 10 of 2 is the solution to the equation […]
Interim analysis, futility monitoring, and predictive probability
An interim analysis of a clinical trial is an unusual analysis. At the end of the trial you want to estimate how well some treatment X works. For example, you want to how likely is it that treatment X works better than the control treatment Y. But in the middle of the trial you want to know something more subtle. It’s […]
...49505152535455565758...