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-18 06:02
Learning languages with the help of algorithms
Suppose you're learning a new language and want to boost your vocabulary in a very time-efficient way. People have many ways to learn a language, different for each person. Suppose you wanted to improve your vocabulary by reading books in that language. To get the most impact, you'd like to pick books that cover as [...]The post Learning languages with the help of algorithms first appeared on John D. Cook.
Mental math posts
I've written quite a few posts on mental math over the years. I think mental math is important/interesting for a couple reasons. First, there is some utility in being able to carry out small calculations with rough accuracy without having stop and open up a calculator. Second, the constraints imposed by mental calculation make you [...]The post Mental math posts first appeared on John D. Cook.
Morse code beyond the solar system
The two Voyager probes, launched in 1977, are now in interstellar space beyond our solar system. Each carries a Golden Record, a recording of sounds and encoded images meant to represent Earth and human civilization. I've long intended to listen to the record and yesterday I did. One of the cuts is a 12-minute collage [...]The post Morse code beyond the solar system first appeared on John D. Cook.
Cycles in Marsaglia’s mental RNG
Last week I wrote about a mental random number generator designed by George Marsaglia. It's terrible compared to any software RNG, but it produces better output than most people would if asked to say a list of random digits. Marsaglia's RNG starts with a two-digit number as a seed state, then at each step replacesn [...]The post Cycles in Marsaglia's mental RNG first appeared on John D. Cook.
Monero’s seed phrase words
I wrote a couple posts last month about the seed phrase words used by Bitcoin and other cryptocurrencies. There are 2048 words on theBIP39 list. Monero uses a different word list, one with 1626 words [1]. You can find Monero's list here. Why 1626 words? It's not hard to guess why the BIP 39 list [...]The post Monero's seed phrase words first appeared on John D. Cook.
Area of the unit disk after a Möbius transformation
Let f(z) = (az + b)/(cz + d) where = ad - bc 1. Iff has no singularity inside the unit disk, i.e. if |d/c| > 1, then the image of the unit disk under f is another disk. What is the area of that disk? The calculation is complicated, but the result [...]The post Area of the unit disk after a Mobius transformation first appeared on John D. Cook.
More triangle inequalities
Yesterday I wrote about a triangle inequality discovered by Paul Erds. LetPbe a point inside a triangleABC. Letx,y,zbe the distances fromPto the vertices and letp,q,r, be the distances to the sides. Then Erds' inequality says x+y+z>= 2(p+q+r). Using the same notation, here are four more triangle inequalities discovered by Oppenheim [1]. px + qy + [...]The post More triangle inequalities first appeared on John D. Cook.
Area of unit disk under a univalent function
LetD be the unit disk in the complex plane and letf be a univalent function on D, meaning it is analytic and one-to-one on D. There is a simple way to compute the area off(D) from the coefficients in its power series. If then The first equality follows from the change of variables theorem for [...]The post Area of unit disk under a univalent function first appeared on John D. Cook.
Random samples from a polygon
Ted Dunning left a comment on my post on random sampling from a triangle saying you could extend this to sampling from a polygon by dividing the polygon into triangles, and selecting a triangle each time with probability proportional to the triangle's area. To illustrate this, let's start with a irregular pentagon. To pick a [...]The post Random samples from a polygon first appeared on John D. Cook.
A triangle inequality by Erdős
Plane geometry has been studied since ancient times, and yet new results keep being discovered millennia later, including elegant results. It's easy to come up with a new result by proving a complicated theorem that Euclid would not have cared about. It's more impressive to come up with a new theorem that Euclid would have [...]The post A triangle inequality by Erds first appeared on John D. Cook.
Randomly selecting points inside a triangle
If you have a triangle with verticesA,B, andC, how would you generate random points inside the triangleABC? Barycentric coordinates One idea would be to use barycentric coordinates. Generate random numbers , , and from the interval [0, 1]. Normalize the points to have sum 1 by dividing each by their sum. Return A + [...]The post Randomly selecting points inside a triangle first appeared on John D. Cook.
A mental random number generator
George Marsaglia was a big name in random number generation. I've referred to his work multiple times here, most recently in this article from March on randomly generating points on a sphere. He is best remembered for his DIEHARD battery of tests for RNG quality. See, for example, this post. I recently learned about a [...]The post A mental random number generator first appeared on John D. Cook.
New symbols in Unicode 17
Unicode 17.0 was released yesterday. According to the announcement This version adds 4,803 new characters, including four new scripts, eight new emoji characters, as well as many other characters and symbols, bringing the total of encoded characters to 159,801. My primary interest in Unicode is for symbols. Here are some of the new symbols I [...]The post New symbols in Unicode 17 first appeared on John D. Cook.
Mandelbrot and Fat Tails
The Mandelbrot set is the set of complex numbers csuch that iterations of f(z) =z^2 +c remain bounded. But how do you know an iteration will remain bounded? You know when it becomes unbounded-if |z| > 2 then the point isn't coming back-but how do you know whether an iteration will never become unbounded? You [...]The post Mandelbrot and Fat Tails first appeared on John D. Cook.
Bech32 encoding
Bech32 is an algorithm for encoding binary data, specifically Bitcoin addresses, in a human-friendly way using a 32-character alphabet. The Bech32 alphabet includes lowercase letters and digits, removing the digit 1, and the letters b, i, and o. The Bech32 alphabet design is similar to that for other coding schemes in that it seeks to [...]The post Bech32 encoding first appeared on John D. Cook.
Inferring sample size from confidence interval
The previous post reported that a study found a 95% confidence interval for the the area of the Mandelbrot set to be 1.506484 0.000004. What was the sample size that was used to come to that conclusion? A 95% confidence interval for a proportion is given by and so if a confidence interval of [...]The post Inferring sample size from confidence interval first appeared on John D. Cook.
Mandelbrot area and escape times
The two latest posts have been about the Mandelbrot set, the set ofcomplex numbers csuch that iterations of f(z) =z^2 +c remain bounded. It's easy to see that the sequence of iterates will go off to infinity if at any step |z| > 2. For eachc, we can look at the escape time, the number [...]The post Mandelbrot area and escape times first appeared on John D. Cook.
Mandelbrot points of every period
As mentioned in the previous post, most of the area in the Mandelbrot set comes from two regions. The largest is the blue cardioid region below and the next largest is the orange disk. The blue cardioid is the set of pointsc such that iterations of z^2 + c converge to a fixed point. The [...]The post Mandelbrot points of every period first appeared on John D. Cook.
Minimalist Mandelbrot set
The Mandelbrot set is one of the most famous fractals. It consists of the complex numbers c such that iterations of f(z) = z^2 + c are bounded. The plot of the Mandelbrot set is a complicated image-it's a fractal, after all-and yet there's a simple description of an first approximation to the Mandelbrot set. [...]The post Minimalist Mandelbrot set first appeared on John D. Cook.
Measuring cryptographic strength in liters of boiling water
I was listening to a podcast with Bill Buchanan recently in which he demonstrated the difficulty of various cryptographic tasks by the amount of energy they would use and how much water that would boil. Some tasks would require enough energy to boil a teaspoon of water, some a swimming pool, and some all the [...]The post Measuring cryptographic strength in liters of boiling water first appeared on John D. Cook.
Impossible rational triangles
A rational triangle is a triangle whose sides have rational length and whose area is rational. Can any two rational numbers be sizes of a rational triangle? Surprisingly no. You can always find a third side of rational length, but it might not be possible to do so while keeping the area rational. The following [...]The post Impossible rational triangles first appeared on John D. Cook.
Trigamma
The most important mathematical function after the basics is the gamma function. If I could add one function to a calculator that has trig functions, log, and exponential, it would be the gamma function. Or maybe the log of the gamma function; it's often more useful than the gamma function itself because it doesn't overflow [...]The post Trigamma first appeared on John D. Cook.
Vanity addresses
Bitcoin addresses are essentially hash values of public keys encoded in Base58. More details here. The addresses are essentially random characters chosen from the Base58 alphabet: uppercase and lowercase Latin letters and digits, with 0 (zero), I (capital I), O (capital O), and l (lowercase l) removed to prevent errors. You could create an address [...]The post Vanity addresses first appeared on John D. Cook.
An integral theorem of Gauss
Gauss proved in 1818 that the value of integral is unchanged ifx andy are replaced by (x +y)/2 and (xy), i.e. if you replacedx andy with their arithmetic mean and geometric mean [1]. So, for example, if you wanted to compute you could instead compute Notice that the coefficients of sin^2 and cos^2 [...]The post An integral theorem of Gauss first appeared on John D. Cook.
El Salvador’s Bitcoin and Quantum Computing
The treasury of El Salvador owns over 6,000 Bitcoins. Its total holdings are currently worth roughly $700,000,000. These coins had been associated with one private key. Yesterday El Salvador announced that it would split its funds into 14 wallets in order to protect the funds from quantum computing. You can confirm using a blockchain explorer [...]The post El Salvador's Bitcoin and Quantum Computing first appeared on John D. Cook.
How quantum computing would affect Bitcoin
Bitcoin relies on two kinds of cryptography: digital signatures and hash functions. Quantum computing would be devastating to the former, but not the latter. To be more specific, the kind of digital signatures used in Bitcoin could in theory be broken by quantum computer using Shor's algorithm. Digital signatures could use quantum-resistant algorithms [1], but [...]The post How quantum computing would affect Bitcoin first appeared on John D. Cook.
Storing data in images
This post will connect a couple posts from yesterday and explore storing data in images. Connections There's a connection between two blog posts that I wrote yesterday that I only realized today. The first post was about the probability of sending money to a wrong Bitcoin address by mistyping. Checksums make it extremely unlikely that [...]The post Storing data in images first appeared on John D. Cook.
An uncrossed knight’s tour
I've written several times about knight's tours of a chessboard. The paths in these tours cross each other many times. What if you wanted to look tours that do not cross themselves? You can't reach every square this way. You can reach half of them, but no more than half. The following tour is part [...]The post An uncrossed knight's tour first appeared on John D. Cook.
Dithered QR codes
I saw a post by Dave Richeson on Mastodon about making QR codes that look like images. Turns out you can shrink a black square in a QR code by up to a factor of three while keeping the code usable. This gives you the wiggle room to create dithered images. I tried a few [...]The post Dithered QR codes first appeared on John D. Cook.
Probability of typing a wrong Bitcoin address
I heard someone say that Bitcoin is dangerous because you could easily make a typo when entering an address, sending money to the wrong person, and have no recourse. There are dangers associated with Bitcoin, such as losing a private key, but address typos are not a major concern. Checksums There are several kinds of [...]The post Probability of typing a wrong Bitcoin address first appeared on John D. Cook.
Why are CUDA kernels hard to optimize?
Explosive datacenter demand has caused developers to leave no stone unturned in search of higher efficiencies. The DeepSeek team, not satisfied with Nvidia's CUDA libraries, used a virtualized form of assembly language (PTX) to write kernel codes to accelerate their AI computations. Others have attempted to generate optimized kernels using AI, though some results have [...]The post Why are CUDA kernels hard to optimize? first appeared on John D. Cook.
The biggest math symbol
The biggest math symbol that I can think of is the Riemann P-symbol The symbol is also known as the Papperitz symbol because Erwin Papperitz invented the symbol for expressing solutions to Bernard Riemann's differential equation. Before writing out Riemann's differential equation, we note that the equation has regular singular points at a,b, andc. In [...]The post The biggest math symbol first appeared on John D. Cook.
You can’t have everything you want: beta edition
The beta distribution is a conjugate prior for a binomial likelihood function, so it makes posterior probability calculations trivial: you simply add your data to the distribution parameters. If you start with a beta(, ) prior distribution on a proportion , then observes successes and f failures, the posterior distribution on is beta( + [...]The post You can't have everything you want: beta edition first appeared on John D. Cook.
More on seed phrase words
Last week I wrote about how the English seed phrase words for crypto wallets, proposed in BIP39, are not ideal for memorization. This post gives a few more brief thoughts based on these words. Prefix uniqueness The BIP39 words have a nice property that I didn't mention: the words are uniquely determined by their first [...]The post More on seed phrase words first appeared on John D. Cook.
Variations on Knuth’s Twindragon
A couple days ago I wrote about Donald Knuth's expression for the twindragon fractal as a sum of powers ofb = 1 -i. Simone Conradi made a nice animation replacing (1 -i) with exp(2it) (1 - i). The animation loops over values oft. Here's what you get whent = 0.3. And here's what you get [...]The post Variations on Knuth's Twindragon first appeared on John D. Cook.
Intuition for Pick’s Theorem
Pick's theorem is a surprising and useful to find the area of a region formed by connecting dots on a grid. The area is simply A = i +p/2 - 1 wherei is the number of dots in the interior andp is the number of dots on the perimeter. Example For example, the in the [...]The post Intuition for Pick's Theorem first appeared on John D. Cook.
Knuth’s Twindragon
A few days ago I wrote about a random process that creates a fractal known as the Twin Dragon. This post gives a deterministic approach to create the same figure. As far as I can tell, the first reference to this fractal is in a paper by Davis and Knuth in the Journal of Recreational [...]The post Knuth's Twindragon first appeared on John D. Cook.
What’s hierarchical about a hierarchical wallet?
A few days ago I wrote about what's in a crypto wallet. In that post I said that most crypto wallets now are hierarchical deterministic (HD) wallets. And I said that HD wallets are deterministic in the sense that they derive all their keys from a seed phrase. But in what sense are HD wallets [...]The post What's hierarchical about a hierarchical wallet? first appeared on John D. Cook.
Punch Cards and Dollar Bills
Today I learned that the size and shape of a punch card was chosen to be the same as US paper money at the time. At the time a US bank note had dimensions 3.25'' by 7.375''. This was sometime prior to 1929 [1] when the size of a bank note changed to 2.61'' by [...]The post Punch Cards and Dollar Bills first appeared on John D. Cook.
A recipe for creating random fractals
Last week I gave an example of a randomly generated fractal and mentioned that it was a particularly special case of a more general algorithm for generating similar fractals found in [1]." Here's the general pattern. First, create a non-singular matrixM with integer entries and let k be the determinant ofM. LetP be the parallelogram [...]The post A recipe for creating random fractals first appeared on John D. Cook.
When log(x) has the same digits as x
I was skimming through a book [1] the other day and saw the following three equations: log 1.3712885742 = 0.13712885742 log 237.5812087593 = 2.375812087593 log 3550.2601815865 = 3.5502601815865 The sequence of digits is the same on both sides of each equation, except for the position of the decimal point. The book said The determination of [...]The post When log(x) has the same digits as x first appeared on John D. Cook.
Connecting partial sums
Today's exponential sum, like all the exponential sums on the site, is formed by drawing a line between consecutive partial sums of a series involving complex exponentials. The exponential sum page makes an image each day by putting the day's month, day, and year into a formula. Here's today's image based on the sum I [...]The post Connecting partial sums first appeared on John D. Cook.
A lot of seed phrase words are similar
A couple days ago I wrote about how you might go about trying to recover a seed phrase that you had remembered out of order. I said that the list of seed phrase words had been designed to be distinct. Just out of curiosity I computed how similar the words are using Levenshtein distance, also [...]The post A lot of seed phrase words are similar first appeared on John D. Cook.
Factoring Stencils
I recently ran across an article by Katherine Stange [1] on Lehmer's factoring stencils [2]. These stencils were the basis of an effective method for factoring moderately large numbers before the advent of electronic computers. This post will describe the stencils and simulate their use with a Python script. Misconceptions When I started reading [1] [...]The post Factoring Stencils first appeared on John D. Cook.
Recovering a permuted seed phrase
As mentioned in the previous post, crypto wallets often turn a list of words, known as a seed phrase, into private keys. These words come from a list of 211 = 2048 words chosen to be distinct and memorable. You can find the list here. Typically a seed phrase will contain 12 words. For example: [...]The post Recovering a permuted seed phrase first appeared on John D. Cook.
What’s in your wallet?
What's in your Bitcoin wallet? Very little. I don't mean very little value, but very little data. If you're a Bitcoin billiionaire, your wallet still doesn't contain very many bits. You might reasonably expect that a crypto wallet is a container, given the analogy with an ordinary wallet, but it's not much of a container. [...]The post What's in your wallet? first appeared on John D. Cook.
Randomly generated dragon
Here's a simple way to generate a fractal known as the Twin Dragon. Start with random values of x andy and repeatedly update the according to the rule xnew = (- xold + yold)/2 - b ynew = (- xold - yold)/2 where b is randomly chosen to be 0 or 1 with equal probability. [...]The post Randomly generated dragon first appeared on John D. Cook.
Converting very long strings to integers in Python
In the process of writing the previous post, I wanted to confirm that the number in the post really is prime. This was useful in debugging my manual conversion of the image to text: errors did not result in a prime number. For example, I didn't see the 9's in the image at first, and [...]The post Converting very long strings to integers in Python first appeared on John D. Cook.
American Flag Prime
The following prime number looks like a black-and-white image of an American flag. The number mostly consists of the digits 1, 3, and 8, but there are a few 9's. The following image colors the 8's blue, the 3's red, and the 1's white. The background is gray so you can see the 1s. I [...]The post American Flag Prime first appeared on John D. Cook.
Uppercase Eszett
I've typed Karl Weierstrass' name quite a few times lately and thought about how you'll sometimes see his name written as Weierstra in English text. That led me to look up the rules for when to use and when to use ss. The rules are moderately complicated, and have varied over time and location. [...]The post Uppercase Eszett first appeared on John D. Cook.
12345678910...