GPS satellites all orbit at the same altitude. According to the FAA, GPS satellites fly in circular orbits at an altitude of 10,900 nautical miles (20,200 km) and with a period of 12 hours. Why were these orbits chosen? You can determine your position using satellites that are not in circular orbits, but with circular […] The post GPS satellite...
A few weeks ago I wrote about the Mellin transform. Mitchell Wheat left comment saying the transform seems reminiscent of Ramanujan’s master theorem, which motivated this post. Suppose you have a function f that is nice enough to have a power series. Now focus on the coefficients an as a function of k. We’ll introduce […] The post Ramanujan’s...
Here’s a simple calculation that I’ve done often enough that I’d like to save the result for my future reference and for the benefit of anyone searching on this. A linear combination of sines and cosines a sin(x) + b cos(x) can be written as a sine with a phase shift A sin(x + φ). […] The post Linear combination of sine and cosine as phase shift...
Suppose you want to write a shell script searches the current directory for files that have a keyword in the name of the file or in its contents. Here’s a first attempt. find . -name '*.py' -type f -print0 | grep -i "$1" find . -name '*.py' -type f -print0 | xargs -0 grep -il […] The post Resolving a mysterious problem with find first appeared on...
I recently stumbled upon the Postage Stamp Problem. Given two relatively prime positive numbers a and b, show that any sufficiently large number N, there exists positive integers x and y such that ax + by = N. I initially missed the constraint that x and y must be positive, in which result is well […] The post The Postage Stamp Problem first...
I’ve read some math publications from around a century or so ago, and I wondered if I could pull off being a math professor if a time machine dropped me into a math department from the time. I think I’d come across as something of an autistic savant, ignorant of what contemporaries would think of […] The post Impersonating an Edwardian math...
Before Copernicus promoted the heliocentric model of the solar system, astronomers added epicycle on top of epicycle, creating ever more complex models of the solar system. The term epicycle is often used derisively to mean something ad hoc and unnecessarily complex. Copernicus’ model was simpler, but it was less accurate. The increasingly...
Suppose you want to interpolate a set of data points with a combination of sines and cosines. One way to approach this problem would be to set up a system of equations for the coefficients of the sines and cosines. If you have N data points, you will get a system of N equations in […] The post Trigonometric interpolation first appeared on John D....
This is a quick note to mention a connection between two recent posts, namely today’s post about moments and post from a few days ago about the Laplace transform. Let f(t) be a function on [0, ∞) and F(s) be the Laplace transform of f(t). Then the nth moment of f, is equal to then nth derivative […] The post Moments with Laplace first appeared on...
It’s fascinating that there’s such a thing as the World Jigsaw Puzzle Championship. The winning team of the two-person thousand-piece puzzle round can assemble a Ravensburger puzzle in less than an hour—that’s about 3 -1/2 seconds per piece. It makes you wonder, how could you measure the hardness of a jigsaw puzzle? And what would […] The post...
The use of the word “moment” in mathematics is related to its use in physics, as in moment arm or moment of inertia. For a non-negative integer n, the nth moment of a function f is the integral of xn over the function’s domain. Uniqueness If two continuous functions f and g have all the […] The post When do moments determine a function? first...
In the early days of computing hardware (and actually before) mathematicians put a lot of effort into understanding and mitigating the limitations of floating point arithmetic. They would analyze mundane tasks such as adding a list of numbers and think carefully about the best way to carry out such tasks as accurately as possible. Now […] The...
I’ve been writing code for the Z3 SMT solver for several months now. Here are my findings. Python is used here as the base language. Python/Z3 feels like a two-layer programming model—declarative code for Z3, imperative code for Python. In this it seems reminiscent of C++/CUDA programming for NVIDIA GPUs—in that case, mixed CPU and […] The post...
I’ve been writing code for the Z3 SMT solver for several months now. Here are my findings. Python is used here as the base language. Python/Z3 feels like a two-layer programming model—declarative code for Z3, imperative code for Python. In this it seems reminiscent of C++/CUDA programming for NVIDIA GPUs—in that case, mixed CPU and […] The post...
The band-limited expansion of the function f(x) is given by where sinc(x) = sin(πx)/πx. This is also called the sinc expansion, or the Whittaker cardinal after its discoverer E. T. Whittaker [1]. This is called the band-limited expansion of f because each term in the infinite sum is band-limited, i.e. only has Fourier spectrum within […] The post...
Sometimes the future state of a system depends not only on the current state (position, velocity, acceleration, etc.) but also on the previous state. Equations for modeling such systems are known as delay differential equations (DDEs), difference differential equations, retarded equations, etc. In a system with hysteresis, it matters not only...
The way Laplace transforms, as presented in a typical differential equation course, are not very useful. Laplace transforms are useful, but not as presented. The use of Laplace transforms is presented is as follows: Transform your differential equation into an algebraic equation. Solve the algebraic equation. Invert the transform to obtain your...
The Mellin transform of a function f is defined as For example, it follows directly from the definition that the gamma function Γ(s) is the Mellin transform of the function e−x. I ran across an exercise that states an impressive-looking theorem about the Mellin transform, namely that where F(s) denotes the Mellin transform of f(x). […] The post...
I woke up around 3:00 this morning to some sort of alarm outside. It did not sound like a car alarm; it sounded like a sawtooth wave. The pattern was like a Morse code O. Not SOS, or I would have gotten up to see if anyone needed help. Just O. A sawtooth wave takes […] The post Sawtooth waves first appeared on John D. Cook.
“A mathematician’s reputation rests on the number of bad proofs he has given. (Pioneer work is clumsy.)” — A. S. Besicovitch I’m sure I’ve written about this quote somewhere, but I can’t find where. The quote comes from A Mathematician’s Miscellany by J. E. Littlewood, citing Besicovitch. I’ve more often seen the quote concluding with […] The...
Mersenne numbers have the form 2p − 1. A Mersenne prime is a Mersenne number that is also a prime. A new Mersenne prime discovery was announced today: 2p − 1 is prime for p = 2136279841. The size of the new Mersenne prime is consistent with what was predicted. For many years now, the […] The post New Mersenne prime found first appeared on John D....
Claude Shannon’s famous paper A Mathematical Theory of Communication [1] includes an example saying that the channel capacity of a telegraph is log2 W where W is the largest real root of the determinant equation Where in the world did that come from? I’ll sketch where the equation above came from, but first let’s find […] The post Channel...
I ran across the following theorem in Ross Honsberger’s book Mathematical Morsels: Every odd square ends in 1 in base 8, and if you cut off the 1 you have a triangular number. A number is an odd square if and only if it is the square of an odd number, so odd squares have […] The post Squares, triangles, and octal first appeared on John D. Cook.
Most random number generators are pseudorandom number generators (PRNGs). The distinction may be pedantic or crucial, depending on context. In the context of cryptography, it’s critical. For this post, RNG will mean a physical, true random number generator. A PRNG may be suitable for many uses—Monte Carlo simulation, numerical integration, game...
Let a, b, and c be the sides of a triangle. Let r be the radius of an inscribed circle and R the radius of a circumscribed circle. Finally, let p be the perimeter. Then the previous post said that 2prR = abc. We could rewrite this as 2rR = abc / (a + b […] The post Triangle circle maximization problem first appeared on John D. Cook.
Let a, b, and c be the sides of a triangle. Let p be perimeter of the triangle. Let r be the radius of the largest circle that can be inscribed in the triangle, and let R be the radius of the circle through the vertices of the triangle. Then all six numbers can be […] The post Relating six properties of a triangle in one equation first appeared...
Repetitive text compresses efficiently. Text like the lyrics to Jingle Bells ought to compress more efficiently than ordinary prose, assuming the compression algorithm can exploit the repetition. The idea of the Burrows-Wheeler transform is to permute text in before compressing it. The hope is that the permutation will make the repetition in the...
The original form of radio broadcast was amplitude modulation (AM). With AM radio, the changes in the amplitude of the carrier wave carries the signal you want to broadcast. Frequency modulation (FM) came later. With FM radio, changes to the frequency of the carrier wave carry the signal. I go into the mathematical details of […] The post Why...
It’s interesting to visualize functions of a complex variable, even very simple functions like f(z) = 1/z. The previous post looked at what happens to triangles under the reciprocal map w = 1/z. This post will look at the same map applied to a polar grid, then look at the effect a shift has, replacing […] The post Shifted reciprocal first...
The set of functions of the form f(z) = (az + b)/(cz + d) with ad ≠ bc are called bilinear transformations or Möbius transformations. These functions have three degrees of freedom—there are four parameters, but multiplying all parameters by a constant defines the same function—and so you can uniquely determine such a function by […] The post...
A golden ellipse is an ellipse whose axes are in golden proportion. That is, the ratio of the major axis length to the minor axis length is the golden ratio φ = (1 + √5)/2. Draw a golden ellipse and its inscribed and circumscribed circles. In other words draw the largest circle that can fit […] The post Golden ellipse first appeared on John D....
Barycentric coordinates are sometimes called area coordinates or areal coordinates in the context of triangle geometry. This is because the barycentric coordinates of a point P inside a triangle ABC correspond to areas of the three triangles PBC, PCA and PAB. (This assumes ABC has unit area. Otherwise divide the area of each of the […] The post...
Let d(n) be the number of divisors of an integer n. For example, d(12) = 6 because 12 is divisible by 1, 2, 3, 4, 6, and 12. The function d varies erratically as the following plot shows. But if you take the running average of d f(n) = (d(1) + d(2) + d(3) + […] The post Average number of divisors first appeared on John D. Cook.
Lucas numbers [1] are sometimes called the companions to the Fibonacci numbers. This sequence of numbers satisfies the same recurrence relation as the Fibonacci numbers, Ln+2 = Ln + Ln+1 but with different initial conditions: L0 = 2 and L1 = 1. Lucas numbers are analogous to Fibonacci numbers in many ways, but are also […] The post Lucas numbers...
Given a hash value, an you determine what algorithm produced it? Or what algorithm probably produced it? Obviously if a hash value is 128 bits long, then a 128-bit algorithm produced it. Such a hash value might have been produced by MD5, but not by SHA-1, because the former produces 128-bit hashes and the latter […] The post Identifying hash...
Random number generators are subtle. Unless the generator is some physical device, random number generators (RNGs) are usually technically pseudorandom number generators (PRNGs), deterministic algorithms designed to mimic randomness. Suppose you have a PRNG that produces the digits 0 through 9. How might you test the output to see whether it...
Why do Venn diagrams almost always show the intersections of three sets and not more? Can Venn diagrams be generalized to show all intersections of more sets? That depends on the rules you give yourself for generalization. If you require that your diagram consist of circles, then three is the limit. As John Venn put […] The post Limitations on...
I was just talking to a colleague about edit distance because it came up in a project we’re working on. Technically, we were discussing Levenshtein distance. It sounds more impressive to say Levenshtein distance, but it’s basically how much editing effort it would take to turn one block of text into another. Edit distance is […] The post Edit...
The birthday problem is a party trick with serious practical applications. It’s well known to people who have studied probability, but the general public is often amazed by it. If you have a group of 23 people, there’s a 50-50 chance that at least two people have the same birthday. With a larger group, say […] The post Birthday problem...
“I keep running into the function f(z) = (1 − z)/(1 + z).” I wrote this three years ago and it’s still true. This function came up implicitly in the previous post. Ramanujan’s excellent approximation for the perimeter of an ellipse with semi-axes a and b begins by introducing λ = (a − b)/(a + […] The post (1 − z) / (1 + z) first appeared on John...
Ramanujan discovered an incredibly accurate approximation for the perimeter of an ellipse. This post will illustrate how accurate the approximation is and push its limits. As with all computations involving ellipses, the accuracy of Ramanujan’s approximation increases as eccentricity increases. But the error increases slowly, and in fact is...
Someone with no exposure to probability or statistics likely has an intuitive sense that averaging random variables reduces variance, though they wouldn’t state it in those terms. They might, for example, agree that the average of several test grades gives a better assessment of a student than a single test grade. But data from a […] The post The...
I recently ran across a theorem connecting the arithmetic mean, geometric mean, harmonic mean, and the golden ratio. Each of these comes fairly often, and there are elegant connections between them, but I don’t recall seeing all four together in one theorem before. Here’s the theorem [1]: The arithmetic, geometric, and harmonic means of two […]...
I keep running into Edward John Routh (1831–1907). He is best known for the Routh-Hurwitz stability criterion but he pops up occasionally elsewhere. The previous post discussed Routh’s mnemonic for moments of inertia and his “stretch” theorem. This post will discuss his triangle theorem. Before stating Routh’s theorem, we need to say what a...
Edward John Routh FRS (1831–1907) came up with a mnemonic for summarizing many formulas for moment of inertia of a solid rotating about an axis through its center of mass. Routh’s mnemonic is I = MS / k where M is the mass of an object, S is the sum of the squares of the […] The post Moments of inertia mnemonic first appeared on John D. Cook.
I recently came across an upper bound I hadn’t seen before [1]. Given a binomial coefficient C(r, k), let n = min(k, r − k) and m = r − n. Then for any ε > 0, C(n + m, n) ≤ (1 + ε)n + m / εn. I could imagine how non-optimal choice […] The post Binomial bound first appeared on John D. Cook.
I was skimming through the book Mathematical Reflections [1] recently. He was discussing a set of generalizations [2] of the Star of David theorem from combinatorics. The theorem is so named because if you draw a Star of David by connecting points in Pascal’s triangle then each side corresponds to the vertices of a triangle. […] The post...
Body Roundness Index (BRI) is a proposed replacement for Body Mass Index (BMI) [1]. Some studies have found that BRI is a better measure of obesity and a more effective predictor of some of the things BMI is supposed to predict [2]. BMI is based on body mass and height, and so it cannot distinguish […] The post Body roundness index first appeared...
I’ve written a couple posts on the approximation by the Indian astronomer Aryabhata (476–550). The approximation is accurate for x in [−π/2, π/2]. The first post collected a Twitter thread about the approximation into a post. The second looked at how far the coefficients in Aryabhata’s approximation are from the optimal approximation as a ratio...
Write the letters of the alphabet around a circle, then strike out the letters that are symmetrical about a vertical line. The remaining letters are grouped in clumps of 3, 1, 4, 1, and 6 letters. I’ve heard that this observation is due to Martin Gardner, but I don’t have a specific reference. The post Finding pi in the alphabet first appeared on...
A few days ago I wrote about the approximation for cosine due to the Indian astronomer Aryabhata (476–550) and gave this plot of the error. I said that Aryabhata’s approximation is “not quite optimal since the ripples in the error function are not of equal height.” This was an allusion to the equioscillation theorem. Chebyshev […] The post...
As mentioned in the previous post, the ratio of consecutive Fibonacci numbers converges to the golden ratio. Is there a sequence whose ratios converge to the silver ratio the way ratios of Fibonacci numbers converge to the golden ratio? (If you’re not familiar with the silver ratio, you can read more about it here.) The […] The post Pell is to...
The number of kilometers in a mile is k = 1.609344 which is close to the golden ratio φ = 1.6180334. The ratio of consecutive Fibonacci numbers converges to φ, and so you can approximately convert miles to kilometers by multiplying by a Fibonacci number and dividing by the previous Fibonacci number. For example, you […] The post Miles to...
This post started out as a Twitter thread. The text below is the same as that of the thread after correcting an error in the first part of the thread. *** The following approximation for sin(x) is remarkably accurate for 0 The post Ancient accurate approximation for sine first appeared on John D. Cook.
This post will give three ways to multiply by π taken from [1]. Simplest approach Here’s a very simple observation about π : π ≈ 3 + 0.14 + 0.0014. So if you need to multiply by π, you need to multiply by 3 and by 14. Once you’ve multiplied by 14 once, you can […] The post Mentally multiply by π first appeared on John D. Cook.
For a standard normal random variable Z, the probability that Z exceeds some cutoff z is given by If you wanted to compute this probability numerically, you could obviously evaluate its defining integral numerically. But as is often the case in numerical analysis, the most obvious approach is not the best approach. The range of […] The post A...
Take a compass and draw a circle on a globe. Then take the same compass, opened to the same width, and draw a circle on a flat piece of paper. Which circle has more area? If the circle is small compared to the radius of the globe, then the two circles will be approximately equal […] The post Drawing with a compass on a globe first appeared on...
The Poisson probability distribution gives a simple, elegant model for count data. You can even derive from certain assumptions that data must have a Poisson distribution. Unfortunately reality doesn’t often go along with those assumptions. A Poisson random variable with mean λ also has variance λ. But it’s often the case that data that would […]...
It is well known that the harmonic series 1 + ½ + ⅓ + ¼ + … diverges. But if you take the denominators as numbers in base 11 or higher, the series converges [1]. I wonder what inspired this observation. Maybe Brewster was bored, teaching yet another cohort of students that the harmonic series […] The post A strange take on the harmonic series...
Suppose you have two normal random variables, X and Y, and that the variance of X is less than the variance of Y. Let M be an equal mixture of X and Y. That is, to sample from M, you first chose X or Y with equal probability, then you choose a sample from the […] The post Variance matters more than mean in the extremes first appeared on John D....
Orbital mechanics is fascinating. I’ve learned a bit about it for fun, not for profit. I seriously doubt Elon Musk will ever call asking me to design an orbit for him. [1] One of the things that makes orbital mechanics interesting is that it can be counter-intuitive. For example, atmospheric friction can make a satellite […] The post Increasing...
Draw a quadrilateral by pick four arbitrary points on a circle and connecting them cyclically. Now multiply the lengths of the pairs of opposite sides. In the diagram below this means multiplying the lengths of the two horizontal-ish blue sides and the two vertical-ish orange sides. Ptolemy’s theorem says that the sum of the two […] The post...
There is a simple rule of thumb for converting between (circular) trig identities and hyperbolic trig identities known as Osborn’s rule: stick an h on the end of trig functions and flip signs wherever two sinh functions are multiplied together. Examples For example, the circular identity sin(θ + φ) = sin(θ) cos(φ) + cos(θ) sin(φ) […] The post...
This weekend I wrote three posts related to interpolation: Compression and interpolation Bessel, Everett, and Lagrange interpolation Binomial coefficients with non-integer arguments The first post looks at reducing the size of mathematical tables by switching for linear to quadratic interpolation. The immediate application is obsolete, but the...
When n and r are positive integers integers, with n ≥ r, there is an intuitive interpretation of the binomial coefficient C(n, r), namely the number of ways to select r things from a set of n things. For this reason C(n, r) is usually pronounced “n choose r.” But what might something like C(4.3, […] The post Binomial coefficients with non-integer...
I never heard of Bessel or Everett interpolation until long after college. I saw Lagrange interpolation several times. Why Lagrange and not Bessel or Everett? First of all, Bessel interpolation and Everett interpolation are not different kinds of interpolation; they are different algorithms for carrying out the same interpolation as Lagrange....
Data compression is everywhere. We’re unaware of it when it is done well. We only become aware of it when it is pushed too far, such as when a photo looks grainy or fuzzy because it was compressed too much. The basic idea of data compression is to not transmit the raw data but to […] The post Compression and interpolation first appeared on John...
Forman Acton’s book Numerical Methods that Work describes Chebyschev polynomials as cosine curves with a somewhat disturbed horizontal scale, but the vertical scale has not been touched. The relation between Chebyshev polynomials and cosines is Tn(cos θ) = cos(nθ). Some sources take this as the definition of Chebyshev polynomials. Other sources...
The convention in math for writing numbers in bases larger than 10 is to insert capital letters after 9, starting with A. So, for example, the digits in base 12 are 0, 1, 2, …, 9, A, and B. So if you’re familiar with math but not Linux, and you run across the base32 utility, […] The post Math’s base 32 versus Linux’s base 32 first appeared on...
I don’t use sed very often, but it’s very handy when I do use it, particularly when needing to make a small change to a large file. Fixing a JSON file Lately I’ve been trying to fix a 30 MB JSON file that has been corrupted somehow. The file is one very long line. Emacs […] The post Editing a file without an editor first appeared on John D. Cook.
Suppose you wanted to approximate Γ(10.3). You know it’s somewhere between Γ(10) = 9! and Γ(11) = 10!, and linear interpolation would give you Γ(10.3) ≈ 0.7 × 9! + 0.3 × 10! = 1342656. But the exact value is closer to 716430.69, and so our estimate is 53% too high. Not a very good […] The post Interpolating the gamma function first appeared on...
One way to find the volume of a sphere would be to imagine the sphere in a box, randomly select points in the box, and count how many of these points fall inside the sphere. In principle this would work in any dimension. The problem with naive Monte Carlo We could write a program to […] The post Too clever Monte Carlo first appeared on John D....
The other day I ran across the surprising identity and wondered how many sums of this form can be evaluated in closed form like this. Quite a few it turns out. Sums of the form evaluate to a rational number when k is a non-negative integer and c is a rational number with |c| > […] The post Evaluating a class of infinite sums in closed form first...
Center a small blue sphere on every corner of an n-dimensional unit hypercube. These are the points in ℝn for which every coordinate is either a 0 or a 1. Now inflate each of these small spheres at the same time until they touch. Each sphere will have radius 1/2. For example, the spheres centered at […] The post Sphere spilling out first appeared...
Imagine in a game of Rock, Paper, Scissors one player is free to play as usual but the other is required to choose each option the same number of times. That is, in 3n rounds of the game, the disadvantaged player much choose Rock n times, Paper n times, and Scissors n times. Obviously the […] The post A variation on Rock, Paper, Scissors first...
The previous post looked at the probability that a random n by n matrix over a finite field of order q is invertible. This works out to be This function of q and n comes up in other contexts as well and has a name that we will get to shortly. Pochhammer symbols Leo August […] The post q-analog of rising powers first appeared on John D. Cook.
If you have n equations in n unknowns over a finite field with q elements, how likely is it that the system of equations has a solution? The number of possible n × n matrices with entries from a field of size q is qn². The set of invertible n × n matrices over a field […] The post Solvability of linear systems over finite fields first appeared on...
Most people implicitly assume medical tests are infallible. If they test positive for X, they assume they have X. Or if they test negative for X, they’re confident they don’t have X. Neither is necessarily true. Someone recently asked me why medical tests always have an error rate. It’s a good question. A test is […] The post Why do medical tests...
Imagine parallel parking is available along the shoulder of a road, but no parking spaces are marked. The first person to park picks a spot on the shoulder at random. Then another car also chooses a spot along the shoulder at random, with the constraint that the second car can’t overlap the first. This process […] The post Rényi’s parking...
When we say that the planets in our solar system orbit the sun, not the earth, we mean that the motions of the planets is much simpler to describe from the vantage point of the sun. The sun is no more the center of the universe than the earth is. Describing the motion of the […] The post Calculating when a planet will appear to move backwards...
Suppose you make an x% improvement followed by a y% improvement. Together do they make an (x + y)% improvement? Maybe. The business principle of kaizen, based on the Japanese 改善 for improvement, is based on the assumption that incremental improvements accumulate. But quantifying how improvements accumulate takes some care. Add or multiply? Two...
I ran across the Clausen function the other day, and when I saw a plot of the function my first thought was that it looks sorta like a sawtooth wave. I wondered whether it also sounds like a sawtooth wave, and indeed it does. More on that shortly. The Clausen function can be defined in […] The post The Clausen function first appeared on John D....
Suppose you’re in a boring meeting and you start doodling. You draw a circle, and then you draw a triangle on the outside of that circle. Next you draw a circle through the vertices of the triangle, and draw a square outside that. Then you draw a circle through the vertices of the square, and […] The post Limit of a doodle first appeared on John...
Healthcare providers in the United States are required to have an ID number known as the NPI (National Provider Identifier). This is a 10-digit unique identifier which serves as the primary key in a publicly available database. You can use the NPI number to look up a provider’s name, credentials, their practice location, etc. The […] The post...
How can you possibly solve a mission-critical problem with millions of variables—when the worst-case computational complexity of every known algorithm for that problem is exponential in the number of variables? SAT (Satisfiability) solvers have seen dramatic orders-of-magnitude performance gains for many problems through algorithmic improvements...
In the previous post I mentioned that the general strategy for computing a mathematical function using tables is to first reduce the function argument to be within the range of the tabulated values, and then to use interpolation to compute the function at values that are not directly tabulated. The second step is always the […] The post Computing...
It takes some skill to use tables of mathematical functions; it’s not quite as simple as it may seem. Although it’s no longer necessary to use tables, it’s interesting to look into the details of how it is done. For example, the Handbook of Mathematical Functions edited by Abramowitz and Stegun tabulates sines and cosines […] The post Calculating...
The previous post looked at two simple approximations for the perimeter of an ellipse. Approximations are necessary since the perimeter of an ellipse cannot be expressed as an elementary function of the axes. Kepler noted in 1609 that you could approximate the perimeter of an ellipse as the perimeter of a circle whose radius is […] The post...
In 1609, Kepler remarked that the perimeter of an ellipse with semiaxes a and b could be approximated either as P1 ≈ 2π(ab)½ or P2 ≈ π(a + b). In other words, you can approximate the perimeter of an ellipse by the circumference of a circle of radius r where r is either the geometric […] The post Kepler’s ellipse perimeter approximations first...
A few days ago I wrote about eigenvector centrality, a way of computing which nodes in a network are most important. Rather than simply looking for the most highly connected nodes, it looks for nodes that are highly connected to nodes that are highly connected. It’s the idea behind Google’s PageRank algorithm. Adjacency matrices One […] The post...
Anyone with more than casual experience with ChatGPT knows that prompt engineering is a thing. Minor or even trivial changes in a chatbot prompt can have significant effects, sometimes even dramatic ones, on the output [1]. For simple requests it may not make much difference, but for detailed requests it could matter a lot. Industry […] The post...
A basic question to ask about a network is which nodes are most important. A simple way of answering this question would be to say the most well-connected nodes, i.e. the nodes with the most edges. This approach is known as degree centrality. It’s not a bad place to start. It’s easy to understand and […] The post Eigenvector centrality first...
The other day I was looking at how many lumens LED lights put put per watt. I found some data on Wikipedia, and as you might expect the relation between watts and lumens is basically linear, though not quite. If you were to do a linear regression on the data you’d get a relation lumens […] The post Fitting a line without an intercept term first...
I read something recently that said in passing that the solutions to the equation tan x = x are the zeros of the Bessel function J3/2. That brought two questions to mind. First, where have I seen the equation tan x = x before? And second, why should its solutions be the roots of a […] The post Solutions to tan(x) = x first appeared on John D. Cook.
The previous post showed how to compute logarithms using tables. It gives an example of calculating a logarithm to 15 figures precision using tables that only allow 4 figures of precision for inputs. Not only can you bootstrap tables to calculate logarithms of real numbers not given in the tables, you can also bootstrap a […] The post Computing...
My favorite quote from Richard Feynman is his remark that “nearly everything is really interesting if you go into it deeply enough.” This post will look at something that seems utterly trivial—looking up numbers in a table—and show that there’s much more to it when you dig a little deeper. More than just looking up […] The post Using a table of...
Excerpt from from John Carmack’s review of the book Bullshit Jobs. He talks about how software developers bemoan duct taping systems together, and would rather work on core technologies. He thinks it is some tragic failure, that if only wise system design was employed, you wouldn’t be doing all the duct taping. Wrong. Every expansion […] The post...
Suppose you design an experiment, an A/B test of two page designs, randomizing visitors to Design A or Design B. You planned to run the test for 800 visitors and you calculated some confidence level α for your experiment. You decide to take a peek at the data after only 300 randomizations, even though your […] The post Condition on your data...
Suppose you’re running an A/B test to determine whether a web page produces more sales with one graphic versus another. You plan to randomly assign image A or B to 1,000 visitors to the page, but after only randomizing 500 visitors you want to look at the data. Is this OK or not? Of course […] The post Can you look at experimental results along...
In LaTeX, sections are labeled with commands like \label{foo} and referenced like \ref{foo}. Referring to sections by labels rather than hard-coded numbers allows references to automatically update when sections are inserted, deleted, or rearranged. For every reference there ought to be a label. A label without a corresponding reference is fine,...
I was reading an article [1] that refers to “a well-known trigonometric series” that I’d never seen before. This paper cites [2] which gives the series as Note that the right hand side is not a series in φ but rather in sin φ. Motivation Why might you know sin φ and want to calculate […] The post A “well-known” series first appeared on John D....
Probability and cryptography have this in common: really smart people can be confidently wrong about both. I wrote years ago about how striking it was to see two senior professors arguing over an undergraduate probability exercise. As I commented in that post, “Professors might forget how to do a calculus problem, or make a mistake […] The post...
Richard Feynman’s Nobel Prize winning discoveries in quantum electrodynamics were partly inspired by his randomly observing a spinning dinner plate one day in the cafeteria. Paul Feyerabend said regarding science discovery, “The only principle that does not inhibit progress is: anything goes” (within relevant ethical constraints, of course)....
The well-known Weierstrass approximation theorem says that polynomials are dense in C [0, 1]. That is, given any continuous function f on the unit interval, and any ε > 0, you can find a polynomial P such that f and P are never more than ε apart. This means that linear combinations of the polynomials 1, […] The post Approximation by prime powers...
I’ve written before about three simple approximations for logarithms, for base 10 log10(x) ≈ (x – 1)/(x + 1) base e, loge(x) ≈ 2(x – 1)/(x + 1) and base 2 log2(x) ≈ 3(x – 1)/(x + 1). These can be used to mentally approximate logarithms to moderate accuracy, accurate enough for quick estimates. Here’s […] The post Logarithm approximation curiosity...
A Mersenne number is a number of the form 2k − 1. A Mersenne prime is a Mersenne number which is also a prime. It turns out that if 2k − 1 is prime then k must be prime, so Mersenne numbers have the form 2p − 1 is prime. What about the converse? If […] The post Iterated Mersenne primes first appeared on John D. Cook.
A video has been making the rounds in which a well-known professor [1] says that if something has a 20% probability of happening in one attempt, then it has a 40% chance of happening in two attempts, a 60% chance in happening in three attempts, etc. This is wrong, but it’s a common mistake. And […] The post Small probabilities add, big ones don’t...
This post is a series of quick thoughts related to logistic regression. It starts with this article on moving between logit and probability scales. *** Logistic regression models the probability of a yes/no event occurring. It gives you more information than a model that simply tries to classify yeses and nos. I advised a client […] The post...
Suppose you’d like to evaluate the function for small values of z, say z = 10−8. This example comes from [1]. The Python code from numpy import exp def f(z): return (exp(z) - 1 - z)/z**2 print(f(1e-8)) prints -0.607747099184471. Now suppose you suspect numerical difficulties and compute your result to 50 decimal places using bc […] The post...
The most obvious way to approximate the derivative of a function numerically is to use the definition of derivative and stick in a small value of the step size h. f′ (x) ≈ ( f(x + h) − f(x) ) / h. How small should h be? Since the exact value of the derivative is the […] The post Numerical differentiation with a complex step first appeared on John...
Bob Carpenter wrote today about how Markov chains cannot thoroughly cover high-dimensional spaces, and that they do not need to. That’s kinda the point of Monte Carlo integration. If you want systematic coverage, you can/must sample systematically, and that’s impractical in high dimensions. Bob gives the example that if you want to get one...
Gian-Carlo Rota made a profound observation on the application of theory. One frequently notices, however, a wide gap between the bare statement of a principle and the skill required in recognizing that it applies to a particular problem. This isn’t quite what he said. I made two small edits to generalize his actual statement. He […] The post Up...
I learned to use the command line utility make in the context of building C programs. The program make reads an input file to tell it how to make things. To make a C program, you compile the source files into object files, then link the object files together. You can tell make what depends […] The post Making documents with makefiles first...
“Good general theory does not search for the maximum generality, but for the right generality.” — Saunders Mac Lane One of the benefits of a scripting language like Python is that it gives you generalizations for free. For example, take the function sorted. If you give it a list of integers, it will return […] The post Applied abstraction first...
One time when I was in grad school, I was a teaching assistant for a business math class that included calculus and a smattering of other topics, including a little bit of probability. I made up examples involving a deck of cards, but then learned to my surprise that not everyone was familiar with playing […] The post A deck of cards first...
The other day I ran across this photo of Saturn’s moon Titan taken by the James Webb Space Telescope (JWST). If JWST can see Titan with this kind of resolution, how well could it see Pluto or other planets? In this post I’ll do some back-of-the-envelope calculations, only considering the apparent size of objects, ignoring […] The post What can...
I ran across a graphic yesterday made by taking a sequence of steps of the same length, turning left on the nth step if n is prime, and otherwise continuing in the same direction. Here’s my recreation of the first 1000 steps: You can see that in general it makes a lot of turns at […] The post Fizz buzz walk first appeared on John D. Cook.
The traditional approach to teaching differential equations is to present a collection of techniques for finding closed-form solutions to ordinary differential equations (ODEs). These techniques seem completely unrelated [1] and have arcane names such as integrating factors, exact equations, variation of parameters, etc. Students may reasonably...
Julia. Scala. Lua. TypeScript. Haskell. Go. Dart. Various computer languages new and old are sometimes proposed as better alternatives to mainstream languages. But compared to mainstream choices like Python, C, C++ and Java (cf. Tiobe Index)—are they worth using? Certainly it depends a lot on the planned use: is it a one-off small project, or […]...
This weekend I ran across a blog post The Rodeo Clown Theory of Personal Development. The title comes from a hypothetical example of a goal you don’t know how to achieve: becoming a rodeo clown. Let’s say you decide you want to be a rodeo clown. And let’s say you’re me and you have no […] The post On greedy algorithms and rodeo clowns first...
There’s a little program called strings that searches for what appear to be strings inside binary file. I’ll refer to it as strings(1) to distinguish the program name from the common English word strings. [1] What does strings(1) consider to be a string? By default it is a sequence of four or more bytes that […] The post Finding strings in binary...
Arshad Khan left a comment on my post on the less and more utilities saying “on ubuntu if I do less on a pdf file, it shows me the text contents of the pdf.” Apparently this is an undocumented feature of GNU less. It works, but I don’t see anything about it in the man […] The post Extract text from a PDF first appeared on John D. Cook.
This post ties together the previous three posts. In this post, I said that an Archimedean spiral has the polar equation r = b θ1/n and applied this here to rolls of carpet. When n = 1, the length of the spiral for θ running from 0 to T is approximately ½ bT² with the […] The post Length of a general Archimedean spiral first appeared on John D....
If you know the dimensions of a carpet, what will the dimensions be when you roll it up into a cylinder? If you know the dimensions of a rolled-up carpet, what will the dimensions be when you unroll it? This post answers both questions. Flexible carpet: solid cylinder The edge of a rolled-up carpet can […] The post How big will a carpet be when...
An Archimedian spiral has the polar equation r = b θ1/n This post will look at the case n = 1. I may look at more general values of n in a future post. The case n = 1 is the simplest case, and it’s the case I needed for the client project that motivated […] The post Approximating a spiral by rings first appeared on John D. Cook.
It’s occasionally necessary to evaluate a hypergeometric function at a large negative argument. I was working on a project today that involved evaluating F(a, b; c; z) where z is a large negative number. The hypergeometric function F(a, b; c; z) is defined by a power series in z whose coefficients are functions of a, […] The post Hypergeometric...
When I first started using Unix, I used a program called “more” to read files. The name makes sense because each time you press the space bar, more will show you more of your file, one screen at a time. Now everyone uses less, and more is all but forgotten. Daniel Halbert wrote more in […] The post More is less first appeared on John D. Cook.
I recently ran across a tweet from Allen Downey saying So much of 20th century statistics was just a waste of time, computing precise answers to useless questions. He’s right. I taught mathematical statistics at GSBS [1, 2] several times, and each time I taught it I became more aware of how pointless some of […] The post Precise answers to...
An article by Y. L. Cheung [1] gives reasons why poker is usually played with five cards. The author gives several reasons, but here I’ll just look at one reason: pairs don’t act like you might expect if you have more than five cards. In five-card poker, the more pairs the better. Better here means […] The post Pairs in poker first appeared on...
Yesterday I stumbled on the fact that the size of Jupiter is roughly the geometric mean between the sizes of Earth and the Sun. That’s not too surprising: in some sense (i.e. on a logarithmic scale) Jupiter is the middle sized object in our solar system. What I find more surprising is that a systematic […] The post Solar system means first...
The size of Jupiter is approximately the geometric mean of the sizes of Sun and Earth. In terms of radii, The ratio on the left equals 9.95 and the ratio on the left equals 10.98. The subscripts are the astronomical symbols for the Sun (☉, U+2609), Jupiter (♃, U+2643), and Earth (, U+1F728). I produced […] The post Earth : Jupiter :: Jupiter :...
I was listening to the latest episode of the Space Rocket History podcast. The show includes some audio from a documentary on Pioneer 11 that mentioned that a man would weigh 500 pounds on Jupiter. My immediate thought was “Is that all?! Is this ‘man’ a 100 pound boy?” The documentary was correct and my […] The post Gravity on Jupiter first...
Are guidance documents laws? Strictly speaking, no. The people who generate such documents are not legislators. Legislators delegate to agencies to make rules, and agencies delegate to other organizations to make guidelines. For example [1], Even HHS, which has express cybersecurity rulemaking authority under the Health Insurance Portability and...
A week or two ago I wrote about Laguerre’s root-finding method and made some associated images. This post gives a couple more examples. Laguerre’s method is very robust in the sense that it is likely to converge to a root, regardless of the starting point. However, it may be difficult to predict which root the […] The post More Laguerre images...
I set up a GitHub account for a new employee this morning and spent a ridiculous amount of time proving that I’m human. The captcha was to listen to three audio clips at a time and say which one contains bird sounds. This is a really clever test, because humans can tell the difference between […] The post A Bayesian approach to proving you’re...
The famous Rule of 72 says that to find out how many years it takes an investment to double in value, divide 72 by the annual percentage rate. I’ll come back to that in a little bit. This morning I read a really good article, Fifty Things you can do with a Software Defined Radio. […] The post Antenna length: Another rule of 72 first appeared on...
AlphaFold 2, FourCastNet and CorrDiff are exciting. AI-driven autonomous labs are going to be a big deal [1]. Science codes now use AI and machine learning to make scientific discoveries on the world’s most powerful computers [2]. It’s common practice for scientists to ask questions about the validity, reliability and accuracy of the mathematical...
I saw someone point out recently that 10! = 7! × 5! × 3! × 1! Are there more examples like this? What would you call the pattern on the right? I don’t think there’s a standard name, but here’s why I think it should be called double super factorial or super double factorial. Super […] The post Double super factorial first appeared on John D. Cook.
Edmond Laguerre (1834–1886) came up with a method for finding zeros of polynomials. Unlike Newton’s method for finding zeros of general functions, Laguerre’s method is specialized for polynomials. Laguerre’s method converges an order of magnitude faster than Newton’s method, i.e. the error is cubed on each step rather than squared. The most...
In the context of medical data, Safe Harbor typically refers to the Safe Harbor provisions of the HIPAA Privacy Rule explained here. Breach Safe Harbor is a little different. It basically means you’re off the hook if you breach encrypted health data. (But not necessarily. More on that below.) I’m not a lawyer, so this […] The post Breach Safe...
Marc Stevens gave an example of two alphanumeric strings that differ in only one byte that have the same MD5 hash value. It may seem like beating a dead horse to demonstrate weaknesses in MD5, but it’s instructive to study the flaws of broken methods. And despite the fact that MD5 has been broken for […] The post MD5 hash collision example first...
Eric Lengyel’s new book Projective Geometric Algebra Illuminated arrived yesterday and I’m enjoying reading it. Imagine if someone started with ideas like dot products, cross products, and determinants that you might see in your first year of college, then thought deeply about those things for years. That’s kinda what the book is. Early in the...
Lately I’ve been helping a colleague to add worker threads to his GUI-based Windows application. Thread programming can be tricky. Here are a few things I’ve learned along the way. Performance. This app does compute-intensive work. It is helpful to offload this very compute-heavy work to a worker thread. Doing this frees the main thread […] The...
One way to approximate π is to find the areas of polygons inscribed inside a circle and polygons circumscribed outside the circle. The approximation improves as the number of sides in the polygons increases. This idea goes back at least as far as Archimedes (287–212 BC). Maybe you’ve tried this. It’s a lot of work. […] The post Accelerating...
Suppose you have a cable of length 2s suspended from two poles of equal height a distance 2x apart. Assuming the cable hangs in the shape of a catenary, how much does it sag in the middle? If the cable were pulled perfectly taut, we would have s = x and there would be no […] The post How much will a cable sag? A simple approximation first...
The word Mississippi has a unique pattern of letters. If you were solving a cryptogram puzzle and saw ZVFFVFFVCCV you might guess that the word is Mississippi. Is the pattern of letters in Mississippi literally unique or just uncommon? What is the shortest word with a unique letter pattern? The longest word? We can answer […] The post Unique...
64 million scientific papers have been published since 1996 [1]. Assuming you can actually find the information you want in the first place—how can you organize your findings to be able to recall and use them later? It’s not a trifling question. Discoveries often come from uniting different obscure pieces of information in a […] The post How to...
Surprise index Warren Weaver [1] introduced what he called the surprise index to quantify how surprising an event is. At first it might seem that the probability of an event is enough for this purpose: the lower the probability of an event, the more surprise when it occurs. But Weaver’s notion is more subtle than […] The post A surprising result...
How would you estimate the size of an author’s vocabulary? Suppose you have a analyzed the author’s available works and found n words, x of which are unique. Then you know the author’s vocabulary was at least x, but it’s reasonable to assume that the author may have know words he never used in writing, […] The post Estimating an author’s...
Imagine you are a code breaker living a century ago. You’ve intercepted a message, and you go through your bag of tricks, starting with the simplest techniques first. Maybe the message has been encrypted using a simple substitution cipher, so you start with that. Simple substitution ciphers can be broken by frequency analysis: the most […] The...
A few years ago I wrote a post about approximating the solution to a differential equation even though the solution did not exist. You can ask a numerical method for a solution at a point past where the solution blows up to infinity, and it will dutifully give you a finite solution. The result is […] The post Blow up in finite time first appeared...
The definition of a subgroup is obvious, but the definition of a normal subgroup is subtle. Widgets and subwidgets The general pattern of widgets and subwidgets is that a widget is a set with some kind of structure, and a subwidget is a subset that has the same structure. This applies to vector spaces and […] The post Normal subgroups are subtle...
The key to solving a lot of elementary what-number-comes-next puzzles is to take first or second differences. For example, if asked what the next item in the series 14, 29, 50, 77, 110, … the answer (or at lest the answer the person posing the question is most likely looking for) is 149. You might […] The post Finite differences and Pascal’s...
This is a guest post by Ondřej Čertík. Ondřej formerly worked at Los Alamos National Labs and now works for GSI Technologies. He is known in the Python community for starting the SymPy project and in the Fortran community for starting LFortran. — John I finally got to experiment a bit with archiving data […] The post Archiving data on paper...
Until recently I used two email services: one to send out daily blog post announcements and another for monthly blog highlights. I’ve combined these into one Substack account for weekly blog highlights. Apparently readers really like this move. Daily and monthly email subscriptions flatlined some time ago, but Substack subscriptions are going up...
Emacs, vi, TextEdit, nano, Sublime, Notepad, Wordpad, Visual Studio, Eclipse, etc., etc.—everyone’s got a favorite. I used Visual Studio previously and liked the integrated debugger. Recently I started using VS again and found the code editing windows rather cluttered. Thankfully you can tone this down, if you can locate the right options....
Suppose you have a triangle and you know the size of the largest circle that can fit inside (the incircle) and the size of the smallest circle that can fit outside (the circumcircle). How would you estimate the perimeter of the triangle? In terms of the figure below, if you know the circumference of the […] The post Bounding the perimeter of a...
The idea of “music of the spheres” dates back to the Pythagoreans. They saw an analogy between orbital frequency ratios and musical frequency ratios. HD 110067 is a star 105 light years away that has six known planets in orbital resonance. The orbital frequencies of the planets are related to each other by small integer […] The post Music of the...
I listened to the 99% Invisible podcast about The Real Book this morning and thought back to my first copy. My first year in college I had a jazz class, and I needed to get a copy of The Real Book, a book of sheet music for jazz standards. The book that was illegal at […] The post The Real Book first appeared on John D. Cook.
The service that sent out my email to blog subscribers stopped working a couple weeks ago, and I’m trying out Substack as a replacement. You can find my Substack account here. My plan for now is to use this account to make blog post announcements, maybe once a week, with a little introductory commentary for […] The post Substack replacing email...
What does the infinite determinant mean and when does it converge? The determinant D above is the limit of the determinants Dn defined by If all the a‘s are 1 and all the b‘s are −1 then this post shows that Dn = Fn, the nth Fibonacci number. The Fibonacci numbers obviously don’t converge, so […] The post Determinant of an infinite matrix first...
I’ve written several posts about how determinants come up in geometry. These determinants often look similar, having columns related to coordinates and a column of ones. You can find several examples here along with an explanation for this pattern. If you have three points z1, z2, and z3 in the complex plane, you can find […] The post Area of...