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-11 01:31
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.
Weierstrass, Montgomery, and Edwards elliptic curve forms
All elliptic curves can be written in Weierstrass form y^2 = x^3 + ax + b with a few exceptions [1]. Montgomery elliptic curves have the form B y^2 =x^3 + A x^2 + x and twisted Edwards curves have the form a x^2 + y^2 = 1 +dx^2 y^2 Every Montgomery curve has a [...]The post Weierstrass, Montgomery, and Edwards elliptic curve forms first appeared on John D. Cook.
Tiny Jubjub
A few days ago I wrote about the Jubjub elliptic curve that takes its name from Lewis Carroll's poem Jabberwocky. I've also written about a slightly smaller but still enormous curve named Baby Jubjub. This post introduces Tiny Jubjub, an elliptic curve with 20 elements, one designed to have some properties in common with its [...]The post Tiny Jubjub first appeared on John D. Cook.
Two ways of generalizing π
The constant is the ratio of a circle's circumference to its diameter. We can generalize by generalizing what a circle is. We will define a p-circle to be the solution to for 1 p . The case ofp = is defined as the limit of the cases ofp asp [...]The post Two ways of generalizing first appeared on John D. Cook.
Misleading plots of elliptic curves
The elliptic curves used in cryptography are over finite fields. They're not curves" at all in the colloquial sense of the word. But they are defined by analogy with continuous curves, and so most discussions of elliptic curves in cryptography start by showing a plot of a real elliptic curve. Here's a plot of y^2 [...]The post Misleading plots of elliptic curves first appeared on John D. Cook.
Memorable Primes
The other day I needed to test some software with a moderately large prime number as input. The first thing that came to mind was 8675309. This would not be a memorable number except it was in the chorus of the song 867-5309/Jenny. It turned out that 8675309 was too large. The software would take [...]The post Memorable Primes first appeared on John D. Cook.
Self-loathing AI
This came out a few weeks ago, but I just learned about it today and I think it's hilarious. Duncan Haldane posted on X a screenshot of Google Gemini having a meltdown. I quit. I am clearly not capable of solving this problem. The code is cursed, the test is cursed, and I am a [...]The post Self-loathing AI first appeared on John D. Cook.
The Rise and Fall of Bayesian Statistics
At one time Bayesian statistics was not just a minority approach, it was considered controversial or fringe. When I was in grad school, someone confided in me that he was a closet Bayesian. He thought the Bayesian approach to statistics made sense, but didn't want to jeopardize his career by saying so publicly. Then somewhere [...]The post The Rise and Fall of Bayesian Statistics first appeared on John D. Cook.
Analyzing the Federalist Papers
The Federalist Papers, a collection of 85 essays published anonymously between 1787 and 1788, were one of the first subjects for natural language processing aided by a computer. Because the papers were anonymous, people were naturally curious who wrote each of the essays. Early on it was determined that the authors were Alexander Hamilton, James [...]The post Analyzing the Federalist Papers first appeared on John D. Cook.
Counting points on an elliptic curve
Suppose you have an elliptic curve y^2 = x^3 + ax + b over a finite field Fpfor prime p. How many points are on the curve? Brute force You can count the number of points on the curve by brute force, as I did here. Loop through each of thep possibilities forx and fory [...]The post Counting points on an elliptic curve first appeared on John D. Cook.
Using TF-IDF to pick out important words
TF-IDF (Term Frequency-Inverse Document Frequency) is commonly used in natural language processing to extract important words. The idea behind the statistic is that a word is important if it occurs frequently in a particular document but not frequently in the corpus of documents the document came from. The term-frequency (TF) of a word in a [...]The post Using TF-IDF to pick out important words first appeared on John D. Cook.
Genesis Block Easter Egg
The White House put out a position paper Strengthening American Leadership in Digital Financial Technology a few days ago. The last page of the paper contains a hex dump. Kinda surprising to see something like that coming out of the White House, but it makes sense in the context of cryptocurrency. Presumably Donald Trump has [...]The post Genesis Block Easter Egg first appeared on John D. Cook.
12345678910...