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-04-06 16:02
HIPAA compliant AI
The best way to run AI and remain HIPAA compliant is to run it locally on your own hardware, instead of transferring protected health information (PHI) to a remote server by using a cloud-hosted service like ChatGPT or Claude. [1]. There are HIPAA-compliant cloud options, but they're both restrictive and expensive. Even enterprise options are [...]The post HIPAA compliant AI first appeared on John D. Cook.
Kalman and Bayes average grades
This post will look at the problem of updating an average grade as a very simple special case of Bayesian statistics and of Kalman filtering. Suppose you're keeping up with your average grade in a class, and you know your average after n tests, all weighted equally. m = (x1 + x2 + x3 + [...]The post Kalman and Bayes average grades first appeared on John D. Cook.
Roman moon, Greek moon
I used the term perilune in yesterday's post about the flight path of Artemis II. When Artemis isclosest to the moon it will be furthest from earth because its closest approach to the moon, its perilune, is on the side of the moon opposite earth. Perilune is sometimes called periselene. The two terms come from [...]The post Roman moon, Greek moon first appeared on John D. Cook.
Hyperbolic version of Napier’s mnemonic
I was looking through an old geometry book [1] and saw a hyperbolic analog of Napier's mnemonic for spherical trigonometry. In hindsight of course there's a hyperbolic analog: there's a hyperbolic analog of everything. But I was surprised because I'd never thought of this before. I suppose the spherical version is famous because of its [...]The post Hyperbolic version of Napier's mnemonic first appeared on John D. Cook.
Artemis II, Apollo 8, and Apollo 13
The Artemis II mission launched yesterday. Much like the Apollo 8 mission in 1968, the goal is to go around the moon in preparation for a future mission that will land on the moon. And like Apollo 13, the mission will swing around the moon rather than entering lunar orbit. Artemis II will deliberately follow [...]The post Artemis II, Apollo 8, and Apollo 13 first appeared on John D. Cook.
Pentagonal numbers are truncated triangular numbers
Pentagonal numbers are truncated triangular numbers. You can take the diagram that illustrates thenth pentagonal number and warp it into the base of the image that illustrates the (2n - 1)st triangular number. If you added a diagram for the (n - 1)st triangular number to the bottom of the image on the right, you'd [...]The post Pentagonal numbers are truncated triangular numbers first appeared on John D. Cook.
Quantum Y2K
I'm skeptical that quantum computing will become practical. However, if it does become practical before we're prepared, the world's financial system could collapse. Everyone agrees we should prepare for quantum computing, even those of us who doubt it will be practical any time soon. Quantum computers exist now, but the question is when and if [...]The post Quantum Y2K first appeared on John D. Cook.
Morse code tree
Peter Vogel posted the following image on X yesterday. The receive side of the coin is a decision tree for decoding Morse code. The shape is what makes this one interesting. Decision trees are typically not very compact. Each branch is usually on its own horizontal level, with diagonal lines going down from each node [...]The post Morse code tree first appeared on John D. Cook.
An AI Odyssey, Part 3: Lost Needle in the Haystack
While shopping on a major e-commerce site, I wanted to get an answer to an obscure question about a certain product. Not finding the answer immediately on the product page, I thought I'd try clicking the AI shopping assistant helper tool to ask this question. I waited with anticipation for an answer I would expect [...]The post An AI Odyssey, Part 3: Lost Needle in the Haystack first appeared on John D. Cook.
Computing sine and cosine of complex arguments with only real functions
Suppose you have a calculator or math library that only handles real arguments but you need to evaluate sin(3 + 4i). What do you do? If you're using Python, for example, and you don't have NumPy installed, you can use the built-in math library, but it will not accept complex inputs. >>> import math >>> [...]The post Computing sine and cosine of complex arguments with only real functions first appeared on John D. Cook.
Lebesgue constants
I alluded to Lebesgue constants in the previous post without giving them a name. There I said that the bound on order ninterpolation error has the form whereh is the spacing between interpolation points and is the error in the tabulated values. The constantc depends on the function f being interpolated, and to a [...]The post Lebesgue constants first appeared on John D. Cook.
How much precision can you squeeze out of a table?
Richard Feynman said that almost everything becomes interesting if you look into it deeply enough. Looking up numbers in a table is certainly not interesting, but it becomes more interesting when you dig into how well you can fill in the gaps. If you want to know the value of a tabulated function between values [...]The post How much precision can you squeeze out of a table? first appeared on John D. Cook.
From Mendeleev to Fourier
The previous post looked at an inequality discovered by Dmitri Mendeleev and generalized by Andrey Markov: Theorem (Markov): If P(x) is a real polynomial of degreen, and |P(x)| 1 on [-1, 1] then |P'(x)| n^2 on [-1, 1]. IfP(x) is a trigonometric polynomial then Bernstein proved that the bound decreases from n^2 ton. Theorem [...]The post From Mendeleev to Fourier first appeared on John D. Cook.
Mendeleev’s inequality
Dmitri Mendeleev is best known for creating the first periodic table of chemical elements. He also discovered an interesting mathematical theorem. Empirical research led him to a question about interpolation, which in turn led him to a theorem about polynomials and their derivatives. I ran across Mendeleev's theorem via a paper by Boas [1]. The [...]The post Mendeleev's inequality first appeared on John D. Cook.
Set intersection and difference at the command line
A few years ago I wrote about comm, a utility that lets you do set theory at the command line. It's a really useful little program, but it has two drawbacks: the syntax is hard to remember, and the input files must be sorted. If A and B are two sorted lists, comm A B [...]The post Set intersection and difference at the command line first appeared on John D. Cook.
Embedded regex flags
The hardest part of using regular expressions is not crafting regular expressions per se. In my opinion, the two hardest parts are minor syntax variations between implementations, and all the environmental stuff outside of regular expressionsper se. Embedded regular expression modifiers address one of the environmental complications by putting the modifier in the regular expression [...]The post Embedded regex flags first appeared on John D. Cook.
A lesser-known characterization of the gamma function
The gamma function (z) extends the factorial function from integers to complex numbers. (Technically, (z + 1) extends factorial.) There are other ways to extend the factorial function, so what makes the gamma function the right choice? The most common answer is the Bohr-Mollerup theorem. This theorem says that if f: (0, ) (0, [...]The post A lesser-known characterization of the gamma function first appeared on John D. Cook.
Tighter bounds on alternating series remainder
The alternating series test is part of the standard calculus curriculum. It says that if you truncate an alternating series, the remainder is bounded by the first term that was left out. This fact goes by in a blur for most students, but it becomes useful later if you need to do numerical computing. To [...]The post Tighter bounds on alternating series remainder first appeared on John D. Cook.
Powers don’t clear fractions
If a number has a finite but nonzero fractional part, so do all its powers. I recently ran across a proof in [1] that is shorter than I expected. Theorem: Supposer is a real number thatis not an integer, and the decimal part ofr terminates. Then rk is not an integer for any positive integer [...]The post Powers don't clear fractions first appeared on John D. Cook.
Tone row operations
The previous post introduced the idea of a twelve-tone row, a permutation of the twelve pitch classes of a chromatic scale. The earlier post also introduced a group of operations on a tone row with elements P, R, I, and RI. Here P, which stands for prime", is the identity operator: it leaves the tone [...]The post Tone row operations first appeared on John D. Cook.
Twelve-tone composition
Atonal music is difficult to compose because it defies human instincts. It takes discipline to write something so unpleasant to listen to. One technique that composers use to keep their music from falling into tonal patterns is the twelve-tone row. The composer creates some permutation of the 12 notes in a chromatic scale and then [...]The post Twelve-tone composition first appeared on John D. Cook.
Langford series
Notice anything special about the following sequence? 8 6 10 3 1 11 1 3 6 8 12 9 7 10 4 2 5 11 2 4 7 9 5 12 Each of the numbers 1 through 12 appear twice. Between the two 1s there is one number. Between the two 2s there are two [...]The post Langford series first appeared on John D. Cook.
Typesetting sheet music with AI
Lilypond is a TeX-like typesetting language for sheet music. I've had good results asking AI to generate Lilypond code, which is surprising given the obscurity of the language. There can't be that much publicly available Lilypond code to train on. I've mostly generated Lilypond code for posts related to music theory, such as the post [...]The post Typesetting sheet music with AI first appeared on John D. Cook.
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.
12345678910...