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 2026-03-13 12:32
Inverse cosine
In the previous two posts, we looked at why Mathematica and SymPy did not simplify sinh(arccosh(x)) to (x^2 - 1) as one might expect. After understanding why sinh(arccosh(x)) doesn't simplify nicely, it's natural to ask why sin(arccos(x)) does simplify nicely. In this post I sketched a proof of several identities including sin(arccos(x)) = (1 - [...]The post Inverse cosine first appeared on John D. Cook.
Simplifying expressions in SymPy
The previous post looked at why Mathematica does not simplify the expression Sinh[ArcCosh[x]] the way you might think it should. This post will be a sort of Python analog of the previous post. SymPy is a Python library that among other things will simplify mathematical expressions. As before, we seek to verify the entries in [...]The post Simplifying expressions in SymPy first appeared on John D. Cook.
sinh( arccosh(x) )
I've written several posts about applying trig functions to inverse trig functions. I intended to write two posts, one about the three basic trig functions and one about their hyperbolic counterparts. But there's more to explore here than I thought at first. For example, the mistakes that I made in the first post lead to [...]The post sinh( arccosh(x) ) first appeared on John D. Cook.
Trig composition table
I've written a couple posts that reference the table below. You could make a larger table, 6 * 6, by including sec, csc, cot, and their inverses, as Baker did in his article [1]. Note that rows 4, 5, and 6 are the reciprocals of rows 1, 2, and 3. Returning to the theme of [...]The post Trig composition table first appeared on John D. Cook.
How much certainty is worthwhile?
A couple weeks ago I wrote a post on a composition table, analogous to a multiplication table, for trig functions and inverse trig functions. Making mistakes and doing better My initial version of the table above had some errors that have been corrected. When I wrote a followup post on the hyperbolic counterparts of these [...]The post How much certainty is worthwhile? first appeared on John D. Cook.
From logistic regression to AI
It is sometimes said that neural networks are just" logistic regression. (Remember neural networks? LLMsare neural networks, but nobody talks about neural networks anymore.) In some sense a neural network is logistic regression with more parameters, alot more parameters, but more is different. New phenomena emerge at scale that could not have been anticipated at [...]The post From logistic regression to AI first appeared on John D. Cook.
An AI Odyssey, Part 2: Prompting Peril
I was working with a colleague recently on a project involving the use of the OpenAI API. I brought up the idea that, perhaps it is possible to improve the accuracy of API response by modifying the API call to increase the amount of reasoning performed. My colleague quickly asked ChatGPT if this was possible, [...]The post An AI Odyssey, Part 2: Prompting Peril first appeared on John D. Cook.
An AI Odyssey, Part 1: Correctness Conundrum
I recently talked with a contact who repeated what he'd heard regarding agentic AI systems-namely, that they can greatly increase productivity in professional financial management tasks. However, I pointed out that though this is true, these tools do not guarantee correctness, so one has to be very careful letting them manage critical assets such as [...]The post An AI Odyssey, Part 1: Correctness Conundrum first appeared on John D. Cook.
Differential equation with a small delay
In grad school I specialized in differential equations, but never worked with delay-differential equations, equations specifying that a solution depends not only on its derivatives but also on the state of the function at a previous time. The first time I worked with a delay-differential equation would come a couple decades later when I did [...]The post Differential equation with a small delay first appeared on John D. Cook.
Shell variable ~-
After writing the previous post, I poked around in the bash shell documentation and found a handy feature I'd never seen before, the shortcut ~-. I frequently use the command cd - to return to the previous working directory, but didn't know about ~- as a shotrcut for the shell variable $OLDPWD which contains the [...]The post Shell variable ~- first appeared on John D. Cook.
Working with file extensions in bash scripts
I've never been good at shell scripting. I'd much rather write scripts in a general purpose language like Python. But occasionally a shell script can do something so simply that it's worth writing a shell script. Sometimes a shell scripting feature is terse and cryptic precisely because it solves a common problem succinctly. One example [...]The post Working with file extensions in bash scripts first appeared on John D. Cook.
Hyperbolic versions of latest posts
The post A curious trig identity contained the theorem that for real xandy, This theorem also holds when sine is replaced with hyperbolic sine. The post Trig of inverse trig contained a table summarizing trig functions applied to inverse trig functions. You can make a very similar table for the hyperbolic counterparts. The following Python [...]The post Hyperbolic versions of latest posts first appeared on John D. Cook.
Trig of inverse trig
I ran across an old article [1] that gave a sort of multiplication table for trig functions and inverse trig functions. Here's my version of the table. I made a few changes from the original. First, I used LaTeX, which didn't exist when the article was written in 1957. Second, I only include sin, cos, [...]The post Trig of inverse trig first appeared on John D. Cook.
A curious trig identity
Here is an identity that doesn't look correct but it is. For realx andy, I found the identity in [1]. The author's proof is short. First of all, Then Taking square roots completes the proof. Now note that the statement at the top assumedx andy are real. You can see that this assumption is necessary [...]The post A curious trig identity first appeared on John D. Cook.
Copy and paste law
I was doing some research today and ran into a couple instances where part of one law was copied and pasted verbatim into another law. I suppose this is not uncommon, but I'm not a lawyer, so I don't have that much experience comparing laws. I do, however, consult for lawyers and have to look [...]The post Copy and paste law first appeared on John D. Cook.
Giant Steps
John Coltrane's song Giant Steps is known for its unusual and difficult chord changes. Although the chord progressions are complicated, there aren't that many unique chords, only nine. And there is a simple pattern to the chords; the difficulty comes from the giant steps between the chords. If you wrap the chromatic scale around a [...]The post Giant Steps first appeared on John D. Cook.
Tritone substitution
Big moves in roots can correspond to small moves in chords. Imagine the 12 notes of a chromatic scale arranged around the hours of a clock: C at 12:00, C at 1:00, D at 2:00, etc. The furthest apart two notes can be is 6 half steps, just as the furthest apart two times can [...]The post Tritone substitution first appeared on John D. Cook.
Bitcoin mining difficulty
The previous post looked at the Bitcoin network hash rate, currently around one zettahash per second, i.e. 1021 hashes per second. The difficulty of mining a Bitcoin block adjusts over time to keep the rate of block production relatively constant, around one block every 10 minutes. The plot below shows this in action. Notice the [...]The post Bitcoin mining difficulty first appeared on John D. Cook.
Exahash, Zettahash, Yottahash
When I first heard of cryptographic hash functions, they were called one-way functions" and seemed like a mild curiosity. I had no idea that one day the world would compute a mind-boggling number of hashes every second. Because Bitcoin mining requires computing hash functions to solve proof-of-work problems, the world currently computes around 1,000,000,000,000,000,000,000 hashes, [...]The post Exahash, Zettahash, Yottahash first appeared on John D. Cook.
10,000,000th Fibonacci number
I've written a couple times about Fibonacci numbers and certificates. Here the certificate is auxiliary data that makes it faster to confirm that the original calculation was correct. This post puts some timing numbers to this. I calculated the 10 millionth Fibonacci number using code from this post. n = 10_000_000 F = fib_mpmath(n) This [...]The post 10,000,000th Fibonacci number first appeared on John D. Cook.
Computing big, certified Fibonacci numbers
I've written before about computing big Fibonacci numbers, and about creating a certificate to verify a Fibonacci number has been calculated correctly. This post will revisit both, giving a different approach to computing big Fibonacci numbers that produces a certificate along the way. As I've said before, I'm not aware of any practical reason to [...]The post Computing big, certified Fibonacci numbers first appeared on John D. Cook.
Visualizing orbital velocity
The shape of a planet's orbit around a star is an ellipse. To put it another way, a plot of the position of a planet's orbit over time forms an ellipse. What about the velocity? Is its plot also an ellipse? Surprisingly, a plot of the velocity forms a circle even if a plot of [...]The post Visualizing orbital velocity first appeared on John D. Cook.
Race between primes of the forms 4k + 1 and 4k + 3
The last few posts have looked at expressing an odd prime p as a sum of two squares. This is possible if and only ifp is of the form 4k + 1. I illustrated an algorithm for finding the squares withp = 2255 - 19, a prime that is used in cryptography. It is being [...]The post Race between primes of the forms 4k + 1 and 4k + 3 first appeared on John D. Cook.
Wagon’s algorithm in Python
The last three posts have been about Stan Wagon's algorithm for finding x and y satisfying x^2 + y^2 = p where p is an odd prime. The first post in the series gives Gauss' formula for a solution, but shows why it is impractical for large p. The bottom of this post introduces Wagon's [...]The post Wagon's algorithm in Python first appeared on John D. Cook.
Finding a square root of -1 mod p
If p is an odd prime, there is a theorem that says x^2 = -1 mod p has a solution if and only if p = 1 mod 4. When a solutionx exists, how do you find it? The previous two posts have discussed Stan Wagon's algorithm for expressing an odd prime p as a [...]The post Finding a square root of -1 mod p first appeared on John D. Cook.
Finding a non-square mod p
The previous post briefly mentioned Stan Wagon's algorithm for expressing an odd prime p as a sum of two squares when it is possible (i.e. when p = 1 mod 4). Wagon's algorithm requires first finding a non-square modp, i.e. a number c such that c d^2 mod p for any d in 1, [...]The post Finding a non-square mod p first appeared on John D. Cook.
Expressing a prime as the sum of two squares
I saw where Elon Musk posted Grok's answer to the prompt What are the most beautiful theorems." I looked at the list, and there were no surprises, as you'd expect from a program that works by predicting the most likely sequence of words based on analyzing web pages. There's only one theorem on the list [...]The post Expressing a prime as the sum of two squares first appeared on John D. Cook.
Aligning one matrix with another
Suppose you have twon * n matrices, A and B, and you would like to find a rotation matrix that lines upB withA. That is, you'd like to find such that A = B. This is asking too much, except in the trivial case ofA andB being 1 * 1 matrices. You could [...]The post Aligning one matrix with another first appeared on John D. Cook.
Computing large Fibonacci numbers
The previous post discussed two ways to compute the nth Fibonacci number. The first is to compute all the Fibonacci numbers up to thenth iteratively using the defining property of Fibonacci numbers Fn + 2 = Fn + Fn + 1 with extended integer arithmetic. The second approach is to use Binet's formula Fn = [...]The post Computing large Fibonacci numbers first appeared on John D. Cook.
Fibonacci numbers and time-space tradeoffs
A few days ago I wrote about Fibonacci numbers and certificates. As I pointed out in the article, there's no need to certify Fibonacci numbers, but the point of the post was to illustrate the idea of a solution certificate in a simple context. Practical uses of certificates are more complicated. This time I want [...]The post Fibonacci numbers and time-space tradeoffs first appeared on John D. Cook.
Minimum of cosine sum
Supposef(x) is the sum of terms of the form cos(kx) wherek is an integer from a set A with nelements. Then the maximum value of f isf(0) =n. But what is the minimum value off? The Chowla cosine conjecture says that the minimum should be less than -n for large n. For now the best [...]The post Minimum of cosine sum first appeared on John D. Cook.
Eigenvalue homework problems are backward
Classroom When you take a linear algebra course and get to the chapter on eigenvalues, your homework problems will include a small matrix A and you will be asked to find the eigenvalues. You do this by computing the determinant det(A - I) = P() and getting P(), a polynomial in . The roots of [...]The post Eigenvalue homework problems are backward first appeared on John D. Cook.
Fibonacci number certificates
Suppose I give you a big numberF and claim thatF is a Fibonacci number. How could you confirm this? Before I go further, let me say what this post is really about. It's not about Fibonacci numbers so much as it is about proofs and certificates. There's no market for large Fibonacci numbers, and certainly [...]The post Fibonacci number certificates first appeared on John D. Cook.
Γ(1/n)
If n is a positive integer, then rounding (1/n) up to the nearest integer givesn. In symbols, We an illustrate this with the following Python code. >>> from scipy.special import gamma >>> from math import ceil >>> for n in range(1, 101): ... assert(ceil(gamma(1/n)) == n) You can find a full proof in [1]. I'll [...]The post (1/n) first appeared on John D. Cook.
Polish serenity
Yesterday I ran across the following mashup by Amy Swearer of a Polish proverb and the Serenity Prayer. Lord, grant me the serenity to accept when it's no longer my circus, the courage to control the monkeys that are still mine, and the wisdom to know the difference. The proverb is Nie moj cyrk, nie [...]The post Polish serenity first appeared on John D. Cook.
Satellites have a lot of room
I saw an animation this morning showing how the space above our planet is dangerously crowded with satellites. That motivated me to do a little back-of-the-envelope math. The vast majority of satellites are in low earth orbit (LEO), which extends from 160 to 2000 km above the earth's surface. The radius of the earth is [...]The post Satellites have a lot of room first appeared on John D. Cook.
AGI, ASI, A*I – Do we have all we need to get there?
Demis: [to get to AGI] maybe there's one or two big innovations needed" Sam: everything based off what we see today is that it will happen." Ilya: But is the belief really that if you just 100x the scale, everything would be transformed? I don't think that's true." Dario: If you just kind of like [...]The post AGI, ASI, A*I - Do we have all we need to get there? first appeared on John D. Cook.
Bridging secrets is hard
Cryptocurrency and privacy don't fit together as easily as you might expect. Blockchains give you the illusion of privacy via pseudonymization: you don't put your name on a blockchain, but you do put information on a blockchain that can be used to determine your name. Blockchain analysis can often reveal information that no one intended [...]The post Bridging secrets is hard first appeared on John D. Cook.
Fortunes and Geometric Means
I saw a post on X recently that said Bill Gates is closer to you in wealth than he is to Elon Musk. Mind blown. For round numbers, let's say Elon Musk's net worth is 800 billion and Bill Gates' net worth is 100 billion. So if your net worth is less 450 billion, the [...]The post Fortunes and Geometric Means first appeared on John D. Cook.
Proving you know a product
There is a way to prove that you know two numbersa andb, and their productc =ab, without revealinga,b, orc. This isn't very exciting without more context - maybe you know that 7 * 3 = 21 - but it's a building block of more interesting zero knowledge proofs, such as proving that a cryptocurrency transaction [...]The post Proving you know a product first appeared on John D. Cook.
How to prove you know a discrete logarithm
In a high school math class, the solution to the equation bx =y is the logarithm ofy in baseb. The implicit context of the equation is the real numbers, and the solution is easy to calculate. The same problem in the context of finite groups is called the discrete logarithm problem, and it is difficult [...]The post How to prove you know a discrete logarithm first appeared on John D. Cook.
Mills ratio and tail thickness
The Mills ratio [1] is the ratio of the CCDF to the PDF. That is, for a random variable X, the Mills ratio at x is the complementary cumulative distribution function divided by the density function. If the density function of X is f, then The Mills ratio highlights an important difference between the Student [...]The post Mills ratio and tail thickness first appeared on John D. Cook.
Sigmas and Student
I saw something yesterday saying that the Japanese bond market had experienced a six standard deviation move. This brought to mind a post I'd written eight years ago. All probability statements depend on a model. And if you're probability model says an event had a probability six standard deviations from the mean, it's more likely [...]The post Sigmas and Student first appeared on John D. Cook.
Stylometry
I was reading an article this morning that mentioned a styometric analysis of a controversial paragraph written by Roman historian Flavius Josephus. I've written several posts that could be called stylometry or adjacent, but I haven't used that word. Here are some posts that touch on the statistical analysis of a text or of an [...]The post Stylometry first appeared on John D. Cook.
Two cheers for ugly code
Ugly code may be very valuable, depending on why it's ugly. I'm not saying that it's good for code to be ugly, but that code that is already ugly may be valuable. Some of the ugliest code was started by someone who knew the problem domain well but did not know how to write maintainable [...]The post Two cheers for ugly code first appeared on John D. Cook.
Prime gaps and Gapcoin
The previous post looked at tightly clustered primes. This post looks at the opposite, large gaps between primes. Riecoin is a cryptocurrency that uses finding prime clusters as its proof of work task. Gapcoin uses finding prime gaps as its proof of work task. There's some nuance to defining prime gaps. It's trivial to produce [...]The post Prime gaps and Gapcoin first appeared on John D. Cook.
Prime clusters and Riecoin
Prime clusters are sets of primes that appear as close together as isgenerally possible. There is one pair of consecutive prime numbers, 2 and 3, but there cannot be any more: in any larger pair of consecutive numbers, one of the pair will be even. But there are a lot of twin primes, perhaps infinitely [...]The post Prime clusters and Riecoin first appeared on John D. Cook.
Efficiently testing multiple primes at once
The previous post looked at a technique for inverting multiple integers modm at the same time, using fewer compute cycles than inverting each integer individually. This post will do something analogous for prime chains, revisiting a post from a few days ago about testing prime chains. A prime chain is a sequence of primes in [...]The post Efficiently testing multiple primes at once first appeared on John D. Cook.
Tighter bounds in the prime number theorem
The most elementary form of the prime number theorem says that (x), the number of prime numbers less than x, is asymptotically equal to x / log(x). That's true, but a more accurate result says (x) is asymptotically equal to li(x) where Five years ago I wrote about a result that was new at the [...]The post Tighter bounds in the prime number theorem first appeared on John D. Cook.
Efficiently computing multiple modular inverses at once
Suppose you have a large prime numberM and you need to find the inverse of several numbers modM. Montgomery's trick is a way to combine the computation of the inverses to take less time than computing the inverses individually. Peter Montgomery (1947-2020) came up with this trick in 1985. We will illustrate Montgomery's trick by [...]The post Efficiently computing multiple modular inverses at once first appeared on John D. Cook.
12345678910...