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 2024-11-22 18:47
Adding phase-shifted sine waves
Suppose you have two sinusoidal functions with the same frequency ω but with different phases and different amplitudes: f(t) = A sin(ωt) and g(t) = B sin(ωt + φ). Then their sum is another sine wave with the same frequency h(t) = C sin(ωt + ψ). Note that this includes cosines as a special case […]The post Adding phase-shifted sine waves first appeared on John D. Cook.
A different kind of computational survival
Last year I wrote a post about being a computational survivalist, someone able to get their work done with just basic command line tools when necessary. This post will be a different take on the same theme. I just got a laptop from an extremely security-conscious client. I assume it runs Windows 10 and that […]The post A different kind of computational survival first appeared on John D. Cook.
Multiply, divide, and floor
Let n be a positive integer and x any real number. If you multiply x by n, then divide by n, of course you get x back. Now suppose you multiply x by n, round down, then divide by n, and round down again. Do you get x back? Not necessarily. The last step rounds down […]The post Multiply, divide, and floor first appeared on John D. Cook.
Continued fractions with period 1
A while back I wrote about continued fractions of square roots. That post cited a theorem that if d is not a perfect square, then the continued fraction representation of d is periodic. The period consists of a palindrome followed by 2⌊√d⌋. See that post for details and examples. One thing the post did not […]The post Continued fractions with period 1 first appeared on John D. Cook.
A bevy of ones
Take any positive integer d that is not a multiple of 2 or 5. Then there is some integer k such that d × k has only 1’s in its decimal representation. For example, take d = 13. We have 13 × 8457 = 111111. Or if we take d = 27, 27 × 4115226337448559670781893 = […]The post A bevy of ones first appeared on John D. Cook.
Symbol pronunciation
I was explaining to someone this evening that I’m in the habit of saying “bang” rather than “exclamation point.” Here’s a list of similar nicknames for symbols. These nicknames could complement the NATO phonetic alphabet if you needed to read symbols out loud, say over the phone. You might, for example, pronounce “HL&P” as “Hotel […]
Is there a zip code that equals its population?
I noticed yesterday that the population in a zip code near me is roughly equal to the zip code itself. So I wondered: Does any zip code equal its population? Yes, it’s a silly question. A zip code isn’t a quantity. Populations are always changing. Zip code boundaries are always changing. Etc. The answer, according […]
Fibonacci numbers and ingrown bark
The previous post looked at the images of concentric circles under functions defined by power series. The terms of these series have the form zθ(n) / θ(n) where θ(n) is a rapidly increasing function of n. These series are thin (technically, lacunary) because all the terms between values of θ(n) are missing. The previous post […]
Concentric circle images go wild
HAKMEM Item 123 gives two plots, both images of concentric circles under functions given by power series with rapidly thinning terms [1]. The first is the function and the second is The lower limits of summation are not given in the original. I assumed at first the sums began at n = 0, but my […]
Accelerating an alternating series
This post looks at an algorithm by Cohen et al [1] to accelerate the convergence of an alternating series. This method is much more efficient than the classical Euler–Van Wijngaarden method. For our example, we’ll look at the series which converges slowly to -π²/12. The first algorithm in [1] for approximating using up to the […]
Compact form of the Lagrange inversion formula
The Lagrange inversion formula can be used to find the power series for the inverse of a function. I wrote about a different approach this problem a couple years ago, that time using Bell polynomials. This time I’ll give a formula that is more direct and easier to remember. Suppose we have a function A(x) […]
Continued fractions of square roots
Let’s look at the continued fraction representation for √14. If we were to take more terms, the sequence of denominators would repeat: 1, 2, 1, 6, 1, 2, 1, 6, 1, 2, 1, 6, … We could confirm this with Mathematica: In: ContinuedFraction[Sqrt[14], 13] Out: {3, 1, 2, 1, 6, 1, 2, 1, 6, 1, […]
Conceptual vs Numerical
One of the things that makes numerical computation interesting is that it often reverses the usual conceptual order of things, using advanced math to compute things that are introduced earlier. Here’s an example I recently ran across [1]. The hyperbolic functions are defined in terms of the exponential function: But it may be more efficient […]
Time spent on the moon
This post will illustrate two things: the amount of time astronauts have spent on the moon, and how to process dates and times in Python. I was curious how long each Apollo mission spent on the lunar surface, so I looked up the timelines for each mission from NASA. Here’s the timeline for Apollo 11, […]
Monthly blog highlights
Once a month I publish a brief newsletter highlighting the top posts from the blog that month. Occasionally I’ll also say something about what I’ve been up to. If you’re interested, you can subscribe here. The same page has links to subscribe to the blog via RSS or email. If you’d like to hear from […]
Hexadecimal floating point
Programming language support for hexadecimal integers is very common. Support for hexadecimal floating point numbers is not. It’s a common convention to put 0x in front of a number to indicate that it is an integer written as an integer literal. For example, 0x12 is not a dozen, but a dozen and a half. The […]
Cesàro summation
There’s more than one way to sum an infinite series. Cesàro summation lets you compute the sum of series that don’t have a sum in the classical sense. Suppose we have an infinite series The nth partial sum of the series is given by The classical sum of the series, if it exists, is defined […]
The worst tool for the job
I don’t recall where I read this, but someone recommended that if you need a tool, buy the cheapest one you can find. If it’s inadequate, or breaks, or you use it a lot, then buy the best one you can afford. (Update: Thanks to Jordi for reminding me in the comments that this comes […]
Not even close
Very often what cannot be done exactly can be done approximately. For example, most integrals cannot be computed in closed form, but they can be calculated numerically as closely as you’d like. But sometimes things are impossible, and you can’t even come close. An impossible assignment When I was in college, I had a friend […]
Overview of NIST post-quantum encryption finalists
If and when large-scale quantum computing becomes practical, most public key encryption algorithms currently in use would be breakable. Cryptographers have known this since Peter Shor published his quantum factoring algorithm in 1994. In 2017 researchers submitted 69 algorithms to the NIST Post-Quantum Cryptography Standardization Process. In 2019 NIST chose 26 of these algorithms to […]
Banned math book
Courant & Hilbert is a classic applied math textbook, still in print nearly a century after the first edition came out. The actual title of the book is Methods of Mathematical Physics, but everyone calls it Courant & Hilbert after the authors, Richard Courant and David Hilbert. I was surprised to find out recently that […]
Hadamard’s upper bound on determinant
For an n by n real matrix A, Hadamard’s upper bound on determinant is where aij is the element in row i and column j. See, for example, [1]. How tight is this upper bound? To find out, let’s write a little Python code to generate random matrices and compare their determinants to Hadamard’s bounds. […]
Cosine power approximation to normal
Ten years ago I wrote about how cosine makes a decent approximation to the normal (Gaussian) probability density. It turns out you get a much better approximation if you raise cosine to a power. If we normalize cosk(t) by dividing by its integral we get an approximation to the density function for a normal distribution […]
Expressiveness
Programmers like highly expressive programming languages, but programing managers do not. I wrote about this on Twitter a few months ago. Q: Why do people like Lisp so much? A: Because Lisp is so expressive. Q: Why don’t teams use Lisp much? A: Because Lisp is so expressive. Q: Why do programmers complain about Java? […]
From shell to system
Routine computer tasks and system programming require different tools, though I’m not entirely sure why. Many people have thought about how inconsistent shells and system programming languages are and tried to unite them. Wouldn’t it be nice to use one language for everything? But attempts to bring system languages down to the shell, or to […]
A warped perspective on math history
Yesterday I posted on @TopologyFact The uniform limit of continuous functions is continuous. John Baez replied that this theorem was proved by his “advisor’s advisor’s advisor’s advisor’s advisor’s advisor.” I assume he was referring to Christoph Gudermann. The impressive thing is not that Gudermann was able to prove this simple theorem. The impressive thing is […]
Decomposing functions of many variables to functions of one variable
Suppose you have a computer that can evaluate and compose continuous functions of one real variable and can do addition. What kinds of functions could you compute with it? You could compute functions of one variable by definition, but could you bootstrap it to compute functions of two variables? Here’s an example that shows this […]
Eliminating polynomial terms
The first step in solving a cubic equation is to apply a change of variables to reduce an equation of the form x³ + bx² + cx + d = 0 to one of the form y³ + py + q = 0. This process can be carried further through Tschirnhausen transformations, a generalization of […]
Leapfrog integrator
The so-called “leapfrog” integrator is a numerical method for solving differential equations of the form where x is a function of t. Typically x is position and t is time. This form of equation is common for differential equations coming from mechanical systems. The form is more general than it may seem at first. It […]
Counterexample to Dirichlet principle
Let Ω be an open set in some Euclidean space and v a real-valued function on Ω. Dirichlet principle Dirichlet’s integral for v, also called the Dirichlet energy of v, is Among functions with specified values on the boundary of Ω, Dirichlet’s principle says that minimizing Dirichlet’s integral is equivalent to solving Laplace’s equation. In […]
Software analysis and synthesis
People who haven’t written large programs think that writing software is easy. All you have to do is break a big problem into smaller problems until you have something so small that it’s easy to program. The problem is putting the pieces back together. If you’ve only written small programs, you haven’t had many pieces […]
COVID19 mortality per capita by state
Here’s a silly graph by Richard West with a serious point. States with longer names tend to have higher covid19 mortality. Of course no one believes there’s anything about the length of a state’s name that should impact the health of its residents. The correlation is real, but it’s a coincidence. The variation between mortality […]
Morse code golf
You can read the title of this post as ((Morse code) golf) or as (Morse (code golf)). Morse code is a sort of approximate Huffman coding of letters: letters are assigned symbols so that more common letters can be transmitted more quickly. You can read about how well Morse code achieves this design objective here. […]
Squircle corner radius
I’ve written several times about the “squircle,” a sort of compromise between a square and a circle. It looks something like a square with rounded corners, but it’s not. Instead of having flat sizes (zero curvature) and circular corners (constant positive curvature), the curvature varies continuously. A natural question is just what kind of circle […]
Triple words
A couple days ago I wrote a post about some doubled words I found on my site. Someone asked about triple words, so I looked. Here are some of the things I found. One example was a post where I commented on a song from Fiddler on the Roof where Teva sings If I were […]
Kissing circle
Curvature is a measure of how tightly a curve bends. A circle of radius r has curvature 1/r. So a small circle has high curvature and a big circle has small curvature. In general the curvature of a curve at a point is defined to be the curvature of the circle that best fits at […]
Double words
Double words such as “the the” are a common source of writing errors. On the other hand, some doubled words are legitimate. You might, for example, find “had had” or “that that” in a grammatically correct sentence. I’ve been looking through my web site to purge erroneous double words, and found a few doubles that […]
Approximating rapidly divergent integrals
A while back I ran across a paper [1] giving a trick for evaluating integrals of the form where M is large and f is an increasing function. For large M, the integral is asymptotically That is, the ratio of A(M) to I(M) goes to 1 as M goes to infinity. This looks like a […]
Best approximation of a catenary by a parabola
A parabola and a catenary can look very similar but are not the same. The graph of y = x² is a parabola and the graph of y = cosh(x) = (ex + e–x)/2 is a catenary. You’ve probably seen parabolas in a math class; you’ve seen a catenary if you’ve seen the St. Louis […]
Five places the Sierpiński triangle shows up
The Sierpiński triangle is a fractal that comes up in unexpected places. I’m not that interested in fractals, and yet I’ve mentioned the Sierpiński triangle many times on this blog just because I run into it while looking at something else. The first time I wrote about the Sierpiński triangle was when it came up […]
Evolute of an egg
The set of lines perpendicular to a curve are tangent to a second curve called the evolute. The lines perpendicular to the ellipse below are tangent to the curve inside called an astroid. If we replace the ellipse with an egg, we get a similar shape, but less symmetric. The equation for the egg is […]
Sample size calculation
If you’re going to run a test on rabbits, you have to decide how many rabbits you’ll use. This is your sample size. A lot of what statisticians do in practice is calculate sample sizes. A researcher comes to talk to a statistician. The statistician asks what effect size the researcher wants to detect. Do […]
Binomial coefficients mod primes
Imagine seeing the following calculation: The correct result is and so the first calculation is off by 25 orders of magnitude. But there’s a variation on the calculation above that is correct! A theorem by Édouard Lucas from 1872 that says for p prime and for any nonnegative integers m and n, So while the […]
Surface of revolution with minimum area
Suppose you’re given two points (x1, y1) and (x2, y2) with y1 and y2 positive. Find the smooth positive curve f(x) that passes through the two points such that the area of the surface formed by rotating the graph of f around the x-axis is minimized. You can state this as a problem in calculus […]
Chemical element frequency in writing
How do the frequencies of chemical element names in English text compare to the abundance of elements in Earth’s crust? Do we write most frequently about the elements that appear most frequently? It turns out the answer is “not really.” The rarest elements rarely appear in writing. We don’t have much to say about dysprosium, […]
Convex function of diagonals and eigenvalues
Sam Walters posted an elegant theorem on his Twitter account this morning. The theorem follows the pattern of an equality for linear functions generalizing to an inequality for convex functions. We’ll give a little background, state the theorem, and show an example application. Let A be a real symmetric n×n matrix, or more generally a […]
Bit flipping to primes
Someone asked an interesting question on MathOverflow: given an odd number, can you always flip a bit in its binary representation to make it prime? It turns out the answer is no, but apparently it is very often the case an odd number is just a bit flip away from being prime. I find that […]
The shape of beams and bulkheads
After finding the NASA publication I mentioned in my previous post, I poked around a while longer in the NASA Technical Reports Server and found a few curiosities. One was that at one time NASA was interested in shapes that similar to the superellipses and squircles I’ve written about before. A report [1] that I […]
NASA’s favorite ODE solver
NASA’s Orbital Flight Handbook, published in 1963, is a treasure trove of technical information, including a section comparing the strengths and weaknesses of several numerical methods for solving differential equations. The winner was a predictor-corrector scheme known as Gauss-Jackson, a method I have not heard of outside of orbital mechanics, but one apparently particularly well […]
Hohmann transfer orbit
How does a spacecraft orbiting a planet move from one circular orbit to another? It can’t just change lanes like a car going around a racetrack because speed and altitude cannot be changed independently. The most energy-efficient way to move between circular orbits is the Hohmann transfer orbit [1]. The Hohmann orbit is an idealization, […]
...25262728293031323334...