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-11-07 21:47
How much is a gigawatt?
There's increasing talk of gigawatt data centers. Currently the largest data center, Switch's Citadel Campus in Nevada, uses 850 megawatts of power. OpenAI's Stargate data center, under construction, is supposed to use 1.2 gigawatts. Gigawatt An average French nuclear reactor produces about a gigawatt of power. If the US were allowed build nuclear reactors, we [...]The post How much is a gigawatt? first appeared on John D. Cook.
Japanese polygon theorem
Here's an interesting theorem that leads to some aesthetically pleasing images. It's known as the Japanese cyclic polygon theorem. For all triangulations of a cyclic polygon, the sum of inradii of the triangles is constant. Conversely, if the sum of inradii is independent of the triangulation, then the polygon is cyclic. The image above shows [...]The post Japanese polygon theorem first appeared on John D. Cook.
Tetrahedral analog of the Pythagorean theorem
A tetrahedron has four triangular faces. Suppose three of those faces come together like the corner of a cube, each perpendicular to the other. Let A1, A2, and A3 be the areas of the three triangles that meet at this corner and let A0 be the area of remaining face, the one opposite the right [...]The post Tetrahedral analog of the Pythagorean theorem first appeared on John D. Cook.
The anti-Smith chart
As I've written about several times lately, the Smith chart is the image of a rectangular grid in the right half-plane under the function f(z) = (z- 1)/(z+ 1). What would the image of a grid in the left half-plane look like? For starters, sincef maps the right half-plane to the interior of the unit [...]The post The anti-Smith chart first appeared on John D. Cook.
Impedance and Triangular Numbers
A few days ago I wrote two posts about how to create a Smith chart, a graphical device used for impedance calculations. Then someone emailed me to point out the connection between the Smith chart and triangular numbers. The Smith chart is the image of a rectangular grid in the right half-plane under the function [...]The post Impedance and Triangular Numbers first appeared on John D. Cook.
Cross ratio
The cross ratio of four pointsA,B,C,D is defined by whereXY denotes the length of the line segment fromX toY. The idea of a cross ratio goes back at least as far as Pappus of Alexandria (c.290 - c.350 AD). Numerous theorems from geometry are stated in terms of the cross ratio. For example, the cross [...]The post Cross ratio first appeared on John D. Cook.
Text case changes the size of QR codes
Let's make a QR code out of a sentence two ways: mixed case and upper case. We'll use Python with the qrcode library. >>> import qrcode >>> s = "The quick brown fox jumps over the lazy dog." >>> qrcode.make(s).save("mixed.png") >>> qrcode.make(s.upper()).save("upper.png") Here are the mixed case and upper case QR codes. The QR code [...]The post Text case changes the size of QR codes first appeared on John D. Cook.
An ancient generalization of the Pythagorean theorem
Apollonius of Perga (c. 262 BC - c. 190 BC) discovered a theorem that generalizes the Pythagorean theorem but isn't nearly as well known. Let ABC be a general triangle, and let D be the midpoint of the segment AB. Leta be the length of the side opposite A andb the length of the side [...]The post An ancient generalization of the Pythagorean theorem first appeared on John D. Cook.
Mentally compute logs base 2
The previous post required computing After writing the post, I thought about how you would mentally approximate log2 5. The most crude approximation would round 5 down to 4 and use log2 4 = 2 to approximate log2 5.That would be good enough for an order of magnitude guess, but we can do much better [...]The post Mentally compute logs base 2 first appeared on John D. Cook.
Physical Keys and Encryption Keys
A physical key, such as a house key, is a piece of metal with cuts of differing depths. Typically there may be around 6 cuts, with five different possible depths for each cut. This allows 56 = 15,625 possible keys. Encryption keys, such as AES keys, are a string of bits, often 128 bits, for [...]The post Physical Keys and Encryption Keys first appeared on John D. Cook.
Freshman’s dream
The Freshman's dream" is the statement (x+ y)p = xp + yp It's not true in general, but itis true modp if p is a prime. It's a cute result, but it's also useful in applications, such as finite field computations in cryptography. Here's a demonstration of the Freshman's dream in Python. >>> p = [...]The post Freshman's dream first appeared on John D. Cook.
Why and how Bitcoin uses Merkle trees
Yesterday's post looked at a recently mined Bitcoin block, the 920,994th block in the blockchain, and verified that it contains the hash of the previous block. This post will look at the same block and verify its Merkle tree root. Before getting down to the bytes, we'll back up and say what a Merkle tree [...]The post Why and how Bitcoin uses Merkle trees first appeared on John D. Cook.
How blocks are chained in a blockchain
The high-level explanation of a blockchain says that each block contains a cryptographic hash of the previous block. That's how the blocks are chained together. That's not exactly true, and it leaves out a lot of detail. This post will look in full detail at how Bitcoin blocks are chained together by inspecting the bits [...]The post How blocks are chained in a blockchain first appeared on John D. Cook.
987654321 / 123456789
I recently saw someone post [1] that 987654321/123456789 is very nearly 8, specifically 8.0000000729. I wondered whether there's anything distinct about base 10 in this. For example, would the ratio of 54321six and 12345six be close to an integer? The ratio is 4.00268, which is pretty close to 4. What about a larger base? Let's [...]The post 987654321 / 123456789 first appeared on John D. Cook.
Spacing the circles on the Smith chart
The previous post looked at the basics of how to create a Smith chart. The Smith chart is the image of a Cartesian grid in the right half-plane under the function f(z) = (z- 1)/(z+ 1). At the end of the post I noted that evenly distributed grid lines in thez plane result in very [...]The post Spacing the circles on the Smith chart first appeared on John D. Cook.
How to make a Smith chart
The Smith chart from electrical engineering is the image of a Cartesian grid under the function f(z) = (z - 1)/(z + 1). More specifically, it's the image of a grid in the right half-plane. This post will derive the basic mathematical properties of this graph but will not go into the applications. Said another [...]The post How to make a Smith chart first appeared on John D. Cook.
Generating random points in Colorado
The previous post looked at how to generate random points on a sphere, generating spherical coordinates directly. I wanted to include a demonstration that this generates points with the same distribution as the more customary way of generating points on a sphere, and then decided the demonstration should be its own post. I'll generate random [...]The post Generating random points in Colorado first appeared on John D. Cook.
Random spherical coordinates
The topic of generating random points on a unit sphere has come up several times here. The standard method using normal random samples generates points (x, y, z) in Cartesian coordinates. If you wanted points in spherical coordinates, you could first generate points in Cartesian coordinates, then convert the points to spherical coordinates. But it [...]The post Random spherical coordinates first appeared on John D. Cook.
Distribution of correlation
One of the more subtle ideas to convey in an introductory statistics class is that statistics have distributions. Students implicitly think that when you calculate a statistic on a data set, say the mean, that then you have THE mean. But if your data are (modeled as) samples from a random variable, then anything you [...]The post Distribution of correlation first appeared on John D. Cook.
Distribution of coordinates on a sphere
Almost Sure posted an interesting fact on X: If a point (x, y, z) is chosen at random uniformly on the unit sphere, then x, y, and z each have the uniform distribution on [-1, 1] and zero correlations (but not independent!) This follows from Archimedes' On the Sphere and Cylinder" published in 225BC. Archimedes [...]The post Distribution of coordinates on a sphere first appeared on John D. Cook.
ODE to Fisher’s transform
I was calculating a correlation coefficient this afternoon and ran into something interesting. Suppose you have two uncorrelated random variablesX andY. If you draw, say, a thousand samples each from X andY and compute Pearson's correlation coefficient, you almost certainly will not get 0, though you very likely will get a small number. How do [...]The post ODE to Fisher's transform first appeared on John D. Cook.
Quality metrics
Sometimes you'll hear that a process has so many nines of reliability or that the error rate is so many sigmas. A few years ago I wrote a post on converting between nines and sigmas. See that post for details, approximations, etc. Here I'd like to post a new graph that I believe is an [...]The post Quality metrics first appeared on John D. Cook.
Turning trig identities into Fibonacci identities
In 2013, John Conway and Alex Ryba published a brief note [1] on how to convert identities involving sine and cosine into identities involving Fibonacci and Lucas numbers. Fibonacci and Lucas The Fibonacci numbers Fn are defined by F0 = 0, F1 = 1, and Fn+2 = Fn + Fn+1 for n > 1. Similarly, [...]The post Turning trig identities into Fibonacci identities first appeared on John D. Cook.
Experiences with GPT-5-Codex
OpenAI Codex is now generally available (see here, here). I'm using the Codex extension in the Cursor code editor with my OpenAI account. Codex is very helpful for some tasks, such as complex code refactoring, implementing skeleton code for an operation, or writing a single small self-contained piece of code. Models have come a long [...]The post Experiences with GPT-5-Codex first appeared on John D. Cook.
Ethereum’s consensus layer elliptic curve
I've written before about Bitcoin's elliptic curve and Monero's elliptic curve. In the Monero post I wrote Bitcoin and Ethereum use the elliptic curvesecp256k1." That's true, but it's incomplete. Ethereum does use the elliptic curve secp256k1 for digital signatures, as does Bitcoin, but Ethereum also uses a different elliptic curve for its consensus layer. Ethereum's [...]The post Ethereum's consensus layer elliptic curve first appeared on John D. Cook.
Inverting matrices and bilinear functions
The inverse of the matrix is the matrix assumingad - bc 0. Also, the inverse of the bilinear function (a.k.a. Mobius transformation) is the function again assumingad - bc 0. The elementary takeaway is that here are two useful equations that are similar in appearance, so memorizing one makes it easy to memorize [...]The post Inverting matrices and bilinear functions first appeared on John D. Cook.
Generate random points inside a sphere
For reasons I don't understand, it's more common, at least in my experience, to see references on how to generate pointson a sphere thanin a sphere. But the latter is easily obtained from the former. The customary way to generate points on a sphere inn dimensions is to generate points from ann-dimensional normal (Gaussian) distribution [...]The post Generate random points inside a sphere first appeared on John D. Cook.
Random samples from a tetrahedron
Exactly one month ago I wrote about sampling points from a triangle. This post will look at the three dimensional analog, sampling from a tetrahedron. The generalization to higher dimensions works as well. Sampling from a triangle In the triangle post, I showed that a naive approach doesn't work but a variation does. If the [...]The post Random samples from a tetrahedron first appeared on John D. Cook.
GPT-5 for AI-assisted discovery
Many hope that AI will be smart enough" to make breakthrough scientific discoveries in the near future, such as find a cure for cancer. Some research efforts have sought to create an AI Scientist" that can make discoveries in an automated or semi-automated way; for a recent example, see [1]. Others [2] have called out [...]The post GPT-5 for AI-assisted discovery first appeared on John D. Cook.
More on Carmichael
This morning I took an old blog post and turned it into an X thread. I think the thread is easier to read. More expository and less rigorous. The post and thread look at generalizations of the fact that every integer and its fifth power end in the same digit. The conclusion is thatn andnk [...]The post More on Carmichael first appeared on John D. Cook.
Differential equation on a doughnut
Here's a differential equation from [1] that's interesting to play with. Even though it's a nonlinear system, it has a closed-form solution, namely where (a,b,c) is the solution att = 0 and = 1 + a^2 + b^2 + c^2. The solutions lie on the torus (doughnut). Ifm andn are coprime integers then the solutions [...]The post Differential equation on a doughnut first appeared on John D. Cook.
Zcash price doubled
My interest in cryptocurrency is primarily technical, and privacy coins are the most technically interesting. The math behind coins like Monero and Zcash is far more sophisticated than the math behind Bitcoin. I'm also interested in the privacy angle since I work in data privacy. The zero-knowledge proof (ZKP) technology developed for and tested in [...]The post Zcash price doubled first appeared on John D. Cook.
RSA with multiple primes
Typically RSA public keys are the product of two large primes,n =pq. But there's no reason they couldn't be the product of say three primes,n =pqr, or more primes, as long as (n), or (n), is calculated correctly. Encryption is done the same way. Decryption could be done the same way, except there is the [...]The post RSA with multiple primes first appeared on John D. Cook.
True growth rate accounting for inflation
In an inflationary economy, the purchasing power of your currency continually deteriorates. If you have an investment that grows slower than your purchasing power shrinks, you're actually losing value over time. The true rate of growth is the rate of change in the purchasing power of your investiment. If the inflation rate is r and [...]The post True growth rate accounting for inflation first appeared on John D. Cook.
A quiet change to RSA
An RSA public key is a pair of numbers (e,n) wheree is an exponent andn =pq wherep andq are large prime numbers. The original RSA paper said choose a private key d and computee. In practice now we choosee and computed. Furthermore, e is now almost always 65537 for reasons given here. So the public [...]The post A quiet change to RSA first appeared on John D. Cook.
Fermat primes and tangent numbers
Fermat numbers The nth Fermat number is defined by Pierre Fermat conjectured that the F(n) were prime for alln, and they are forn = 0, 1, 2, 3, and 4, but Leonard Euler factoredF(5), showing that it is not prime. Tangent numbers Thenth tangent number is defined by the Taylor series for tangent: Another way [...]The post Fermat primes and tangent numbers first appeared on John D. Cook.
Memorizing a list of seed words
If you need to memorize a list of up to eight words, particularly for a short period of time, the most efficient method may be brute force: rehearse the words in sequence until you can remember them. But if you need to remember more words, or remember the list for a longer time, some sort [...]The post Memorizing a list of seed words first appeared on John D. Cook.
10x vs 10%
Several years ago I asked myself a couple questions. Which things, if I were 10x better at, would make little difference? Which things, if I were 10% better at, would make a big difference? I remember realizing, in particular, that if I knew 10x more about statistics, it wouldn't make a bit of difference. The [...]The post 10x vs 10% first appeared on John D. Cook.
Time needed to factor large integers
The optimal choice of factoring algorithm depends on the size of the number you want to factor. For numbers larger than a googol (10100) the GNFS (general number field sieve) algorithm is the fastest known factoring algorithm, making GNFS the algorithm of choice for trying to factor public keys for RSA encryption The expected time [...]The post Time needed to factor large integers first appeared on John D. Cook.
log log x
This post will include some simple but useful calculations. Throughout this post, a and b are real numbers greater than 1. All logs are proportional For any two bases a and b, log base a and log base b are proportional, and in fact the proportionality constant is logb a. We have or to put [...]The post log log x first appeared on John D. Cook.
Fitting a double exponential function to three points
The previous post needed to fit a double exponential function to data, a function of the form By taking logs, we have a function of the form where thea in the latter equation is the log of thea in the former. In the previous post I used a curve fitting function from SciPy to find [...]The post Fitting a double exponential function to three points first appeared on John D. Cook.
Extrapolating quantum factoring
In 2001, a quantum computer was able to factor 15. In 2012, a quantum computer was able to factor 21, sorta. They cheated by not implementing gates that they knew a priori would not be used. To this day, there still hasn't been a quantum computer to factor 21 without taking some shortcuts. Some reasons [...]The post Extrapolating quantum factoring first appeared on John D. Cook.
Post-quantum RSA with gargantuan keys
If and when practical scalable quantum computers become available, RSA encryption would be broken, at least for key sizes currently in use. A quantum computer could use Shor's algorithm factor n-bit numbers in time on the order of n^2. The phrase quantum leap" is misused and overused, but this would legitimately be a quantum leap. [...]The post Post-quantum RSA with gargantuan keys first appeared on John D. Cook.
Conway’s pinwheel tiling
John Conway discovered a right triangle that can be partitioned into five similar triangles. The sides are in proportion 1 : 2 : 5. You can make a larger similar triangle by making the entire triangle the central (green) triangle of a new triangle. Here's the same image with the small triangles filled in as [...]The post Conway's pinwheel tiling first appeared on John D. Cook.
Silent Payments
Bitcoin transactions appear to be private because names are not attached to accounts. But that is not sufficient to ensure privacy; if it were, much of my work in data privacy would be unnecessary. It's quite possible to identify people in data that does not contain any direct identifiers. I hesitate to use the term [...]The post Silent Payments first appeared on John D. Cook.
An inverse problem for the quadratic equation
In elementary algebra we learn how to solve ax2 + bx + c = 0 for roots r = r1, r2. But how about the inverse problem: given a real-valued r, find integer coefficients a, b and c such that r is a root of the corresponding quadratic equation. A simple approximation can be found [...]The post An inverse problem for the quadratic equation first appeared on John D. Cook.
Inverting series that are flat at zero
The previous post looked at solving the equation which arises from the Mollweide map projection. Newton's method works well unless is near /2. Using a modified version of Newton's method makes the convergence faster when = /2, which is kinda useless because we know the solution is $theta; = /2 there. When [...]The post Inverting series that are flat at zero first appeared on John D. Cook.
Mollweide map projection and Newton’s method
Karl Brandan Mollweide (1774-1825) designed an equal-area map projection, mapping the surface of the earth to an ellipse with an aspect ratio of 2:1. If you were looking at the earth from a distance, the face you're looking at would correspond to a circle in the middle of the Mollweide map [1]. The part of [...]The post Mollweide map projection and Newton's method first appeared on John D. Cook.
1420 MHz
There are four manmade object that have left our solar system: Pioneer 10, Pioneer 11, Voyager 1, and Voyager 2. Yesterday I wrote about the Golden Record which is on both of the Voyager probes. Some of the graphics on the cover of the Golden Record is also on plaques attached to the Pioneer probes. [...]The post 1420 MHz first appeared on John D. Cook.
The AI fork in the road
If AI can do part of your job, you're likely to either be fired or promoted. AI will always have some error rate, and if it can do your job at an acceptable error rate, you'll need to find another job. But if the error rate is not acceptable, the ability to identify and fix [...]The post The AI fork in the road first appeared on John D. Cook.
12345678910...