johndcook.com
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 = ( x 1 + x 2 + x 3 + … + x n ) / n . Then you get another test grade back and your new average is m ′ = ( x 1 + x 2 + x 3 + … + x n + x n +1 ) / ( n + 1). You don’t need the individual test grades once you’ve com...
Roman moon, Greek moon
I used the term perilune in yesterday’s post about the flight path of Artemis II. When Artemis is closest 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 two goddesses associated with the moon, the Roman Luna and the Greek Selene. Since the peri- prefix is Greek, perhaps periselene would be preferable. But we’re far more famil...
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 practical use in navigational calculations, while the hyperbolic analog is of more theoretical interest. Napier’s mnemonic is a clev...
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 trajectory around the moon that Apollo 13 took as a fallback. Apollo 8 spent 2 hours and 44 minutes in low earth orbit (LEO) before performing trans-lunar injection (TLI) and heading tow...
Pentagonal numbers are truncated triangular numbers
Pentagonal numbers are truncated triangular numbers. You can take the diagram that illustrates the n th pentagonal number and warp it into the base of the image that illustrates the (2 n − 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 have a diagram for the (2 n − 1)st triangular number. In short, P n = T 2 n − 1 − T n . This is trivial to prove algebraically, though the visual proof above is more interest...
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 a cryptographically relevant quantum computer (CRQC) is coming. At the moment, a quantum computer cannot factor 21 without cheating (i.e...
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 to its children. But by making the lines either horizontal or vertical, the tree fits nicely into a circle. I thought for a second that the designer had made the choices of horizont...
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 be more informative and useful than a standard search result. But it was not to be. The AI tool had nothing worthwhile. Then I decided on an old-fashioned keyword search across a...
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 + 4 i ). 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 >>> math.sin(3 + 4j) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: must be real number, not complex You can use the foll...
Lebesgue constants
I alluded to Lebesgue constants in the previous post without giving them a name. There I said that the bound on order n interpolation error has the form where h is the spacing between interpolation points and δ is the error in the tabulated values. The constant c depends on the function f being interpolated, and to a lesser extent on n . The constant λ is independent of f but depends on n and on the relative spacing between the interpolation nodes. This post will look closer at λ. Given a set of...
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 of x given in the table, you have to use interpolation. Linear interpolation is often adequate, but you could get more accurate results using higher-order interpolation. Suppose you have ...
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 degree n , and | P ( x )| ≤ 1 on [−1, 1] then | P ′( x )| ≤ n ² on [−1, 1]. If P ( x ) is a trigonometric polynomial then Bernstein proved that the bound decreases from n ² to n . Theorem (Bernstein): If P ( x ) is a trigonometric polynomial of degree n , and | P ( z )| ≤ 1 on [−π, π] then | P ′( x )| ≤ n on [−π, π]. Now a trigonometric p...
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 opening paragraph describes what Mendeleev was working on. Some years after the chemist Mendeleev invented the periodic table of the elements he ma...
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 prints A − B, B − A, and A ∩ B. You usually don’t want all three, and so comm lets you filter the output. It’s a little quirky in that you specify what you don’t want instead of what you do. And you have to...
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 expressions per se. Embedded regular expression modifiers address one of the environmental complications by putting the modifier in the regular expression itself. For example, if you want to make a grep search case-insensitive, you pass it the -i flag. But if you want ...
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, ∞) satisfies f ( x + 1) = x f ( x ) f (1) = 1 log f is convex then f ( x ) = Γ( x ). The theorem applies on the positive real axis, and there is a unique holomorph...
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 be more precise, assume we have a series of the form where the a i are positive and monotonically converge to zero. Then the tail of the series is bounded by its first term: The more we can say ab...
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: Suppose r is a real number that is not an integer, and the decimal part of r terminates. Then r k is not an integer for any positive integer k . Proof: The number r can be written as a reduced fraction a / 10 m for some positive m . If s = r k were an integer, then 10 mk s = a k . Now the left side of this equation is divisible by 10 but the r...
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 row alone. R stands for retrograde, which means to reverse the sequence. I stands for inversion, inverting each of the intervals in the row. If you apply R then I, you get the same resu...
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 uses these notes strictly in order. The durations of the notes may vary, and the notes may move up or down octaves, but the pitch classes are recycled over and over in...