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 2025-09-11 18:46
Solving for the catenary scale parameter
A catenary with scale a is the graph of the function f(x; a) = a cosh(x/a) – a. The x and the a are separated by a semicolon rather than a comma to imply that we think of x as the variable and a as a parameter. This graph passes through the origin, i.e. for any […]The post Solving for the catenary scale parameter first appeared on John D. Cook.
Alphabets and Unicode
ASCII codes may seem arbitrary when you’re looking at decimal values, but they make more sense in hex [1]. For example, the ASCII value for 0 is 48. Why isn’t it zero, or at least a number that ends in zero? Well it is, in hex: 0x30. And the codes are in consecutive order, so […]The post Alphabets and Unicode first appeared on John D. Cook.
How much does it matter if the measuring tape sags?
There are a couple ways in which a measurement might not be straight. Yesterday I wrote a blog post about not measuring straight toward your target. You’d like to measure from (0, 0) to (x, 0), but something is in the way, and so you measure from (0, 0) to (x, y), where y is […]The post How much does it matter if the measuring tape sags? first appeared on John D. Cook.
From tape measures to tensors
This post will start with a motivating example, looking at measuring a room in inches and in feet. Then we will segue into a discussion of contravariance and covariance in the simplest setting. Then we will discuss contravariant and covariant tensors more generally. Using a tape measure In my previous post, I explained why it […]The post From tape measures to tensors first appeared on John D. Cook.
It doesn’t matter much if the tape is straight
Suppose a contractor is measuring the length of a wall. He starts in one corner of the room, and lets out a tape measure heading for the other end of the wall. But something is in the way, so instead of measuring straight to the corner, he measures to a point near the corner on […]The post It doesn't matter much if the tape is straight first appeared on John D. Cook.
At the next prime, turn left
The previous post mentioned a Math Overflow question about unexpected mathematical images, and reproduced one that looks like field grass. This post reproduces another set of images from that post. Start anywhere in the complex plane with integer coordinates and walk west one unit at a time until you run into Gaussian prime [1]. Then […]The post At the next prime, turn left first appeared on John D. Cook.
Simple equations whose plot looks like field grass
Math Overflow has an interesting question about unexpected mathematical images. Here’s a response from Payam Seraji that was easy to code up. Here’s the code that produced the image. from numpy import * import matplotlib.pyplot as plt t = linspace(0, 39*pi/2, 1000) x = t*cos(t)**3 y = 9*t*sqrt(abs(cos(t))) + t*sin(0.2*t)*cos(4*t) plt.plot(x, y, c="green") plt.axes().set_aspect(0.3) plt.axis('off')The post Simple equations whose plot looks like field grass first appeared on John D. Cook.
Constructing bilinear transformations
The previous post was a visual introduction to bilinear transformations, a.k.a. Möbius transformations or fractional linear transformations. This post is a short follow-up focused more on calculation. A bilinear transformation f has the form where ad – bc ≠ 0. Inverse The inverse of f is given by The transformation f is defined everywhere except […]The post Constructing bilinear transformations first appeared on John D. Cook.
Circles to Circles
This post expands on something I said in passing yesterday. I said in the body of the post that … the image of a circle in the complex plane under a Möbius transformation is another circle. and added in a footnote that For this to always be true, you have to include a line as […]The post Circles to Circles first appeared on John D. Cook.
Simultaneous projects
I said something to my wife this evening to the effect that it’s best for employees to have one or at most two projects at a time. Two is good because you can switch off when you’re tired of one project or if you’re waiting on input. But with three or more projects you spend […]The post Simultaneous projects first appeared on John D. Cook.
Schwarzian derivative
There are many ways the basic derivative can be generalized: partial derivatives, directional derivatives, covariant derivatives, etc. These all reduce to the basic derivative under the right circumstances. The Schwarzian derivative is not like that. It’s not a generalization of the familiar derivative but rather a differential operator analogous to a derivative. The Schwarzian derivative […]The post Schwarzian derivative first appeared on John D. Cook.
Searching Greek and Hebrew with regular expressions
According to the Python Cookbook, “Mixing Unicode and regular expressions is often a good way to make your head explode.” It is thus with fear and trembling that I dip my toe into using Unicode with Greek and Hebrew. I heard recently that there are anomalies in the Hebrew Bible where the final form of […]The post Searching Greek and Hebrew with regular expressions first appeared on John D. Cook.
Descartes and Toolz
I was looking recently at the Python module toolz, a collection of convenience functions. A lot of these functions don’t do that much. They don’t save you much code, but they do make your code more readable by making it more declarative. You may not realize need them until you see them. For example, there […]The post Descartes and Toolz first appeared on John D. Cook.
Driving vibrations with sawtooth waves
The previous post looked at driving a vibrating system with square waves rather than the more customary sine waves. You could think of a square wave as a crude approximation to a sine wave. A sawtooth wave is another crude approximation to a sine wave, and so it would be interesting to see how systems […]The post Driving vibrations with sawtooth waves first appeared on John D. Cook.
Driving oscillations with square waves
What happens when you drive a vibrating system with a square wave rather than a sine wave? Do you still see the same kinds of behavior, such as beats and resonance? When does the difference between a square wave and a sine wave matter most? Those are the questions this post will address. Background Basic […]The post Driving oscillations with square waves first appeared on John D. Cook.
There’s more going on here
At a new faculty orientation, a professor encouraged us rookies to teach intro courses and to keep coming back to teach them periodically. I didn’t fully appreciate what he said at the time, though I remembered it, even though I left academia a couple years later. Now I think I have an idea what he […]The post There's more going on here first appeared on John D. Cook.
Superfactorial
The factorial of a positive integer n is the product of the numbers from 1 up to and including n: n! = 1 × 2 × 3 × … × n. The superfactorial of n is the product of the factorials of the numbers from 1 up to and including n: S(n) = 1! × […]The post Superfactorial first appeared on John D. Cook.
Symplectic Euler
This post will look at simple numerical approaches to solving the predator-prey (Lotka-Volterra) equations. It turns out that the simplest approach does poorly, but a slight variation does much better. Following [1] we will use the equations u‘ = u (v – 2) v‘ = v (1 – u) Here u represents the predator population over […]The post Symplectic Euler first appeared on John D. Cook.
Identifying someone from their heart beat
How feasible would it be to identify someone based from electrocardiogram (EKG, ECG) data? (Apparently the abbreviation “EKG” is more common in America and “ECG” is more common in the UK.) Electrocardiograms are unique, but unique doesn’t necessarily mean identifiable. Unique data isn’t identifiable without some way to map it to identities. If you shuffle […]The post Identifying someone from their heart beat first appeared on John D. Cook.
Overestimating the number of idiots
A comment on one of my recent blog posts on Gray codes led me to an article by Mark Dominus Gray code at the pediatrician’s office, which led me to his article explaining why the pediatrician used what was apparently an unnecessarily sophisticated piece of equipment. Mark segues from appreciating the pediatrician’s stadiometer purchase to […]The post Overestimating the number of idiots first appeared on John D. Cook.
Inverse Gray code
The previous post looked at Gray code, a way of encoding digits so that the encodings of consecutive integers differ in only bit. This post will look at how to compute the inverse of Gray code. The Gray code of a non-negative integer n is given by def gray(n): return n ^ (n >> 1) […]The post Inverse Gray code first appeared on John D. Cook.
Gray code
Suppose you want to list the numbers from 0 to N in such a way that only one bit at a time changes between consecutive numbers. It’s not clear that this is even possible, but in fact it’s easy using Gray code, a method named after Frank Gray. To convert an integer to its Gray […]The post Gray code first appeared on John D. Cook.
Memorizing numbers and enumerating possibilities
This post will illustrate two things: how to memorize numbers, and how to enumerate products of sets in Python. Major system There’s a way of memorizing numbers by converting digits to consonant sounds, then adding vowels to make memorable words. It’s called the “major” mnemonic system, though it’s not certain where the system or the […]The post Memorizing numbers and enumerating possibilities first appeared on John D. Cook.
Looking at the bits of a Unicode (UTF-8) text file
Suppose you type a little text into a text file, say “123”. If you open this file in a hex editor you’ll see 3132 33 because the ASCII value for the character ‘1’ is 0x31 in hex, ‘2’ corresponds to 0x32, and ‘3’ corresponds to 0x33. If your file is saved as utf-8 rather than […]The post Looking at the bits of a Unicode (UTF-8) text file first appeared on John D. Cook.
How much do you really use?
I’ve been doing a little introspection lately about what software I use, not at an application level but at a feature level. LaTeX It started with looking at what parts of LaTeX I use. I wrote about this in April, and I revisited it this week in response to some client work [1]. LaTeX is […]The post How much do you really use? first appeared on John D. Cook.
Make boring work harder
I was searching for something this morning and ran across several pages where someone blogged about software they wrote to help write their dissertations. It occurred to me that this is a pattern: I’ve seen a lot of writing tools that came out of someone writing a dissertation or some other book. The blog posts […]The post Make boring work harder first appeared on John D. Cook.
Sum of divisor powers
The function σk takes an integer n and returns the sum of the kth powers of divisors of n. For example, the divisors of 14 are 1, 2, 4, 7, and 14. If we set k = 3 we get σ3(n) = 1³ + 2³ + 4³ + 7³ + 14³ = 3096. A couple […]The post Sum of divisor powers first appeared on John D. Cook.
An almost integer pattern in many bases
A few days ago I mentioned a passing comment in video by Richard Boucherds. This post picks up on another off-hand remark from that post. Boucherds was discussing why exp(π √67) and exp(π √163) are nearly an integer. exp(π √67) = 147197952744 – ε1 exp(π √163) = 262537412640768744 – ε2 where ε1 and ε2 and […]The post An almost integer pattern in many bases first appeared on John D. Cook.
Org entities
This morning I found out that Emacs org-mode has its own markdown entities, analogous to HTML entities or LaTeX commands. Often they’re identical to LaTeX commands. For example, \approx is the approximation symbol ≈, exactly as in LaTeX. So what’s the advantage of org-entities? In fact, how does Emacs even know whether \approx is a […]The post Org entities first appeared on John D. Cook.
How big is the monster?
Symmetries are captured by mathematical groups. And just as you can combine kinds symmetry to form new symmetries, you can combine groups to form new groups. So-called simple groups are the building blocks of groups as prime numbers are the building blocks of integers [1]. Finite simple groups have been fully classified, and they fall […]The post How big is the monster? first appeared on John D. Cook.
Square waves and cobwebs
This is a follow-up to yesterday’s post. In that post we looked at iterates of the function f(x) = exp( sin(x) ) and noticed that even iterations of f converged to a square wave. Odd iterates also converge to a square wave, but a different one. The limit of odd iterations is the limit of […]The post Square waves and cobwebs first appeared on John D. Cook.
Unexpected square wave
Last night a friend from Vanderbilt, Father John Rickert, sent me a curious math problem. (John was a PhD student in the math department while I was a postdoc. He went on to be a Catholic priest after graduating.) He said that if you look at iterates of f(x) = exp( sin(x) ) the plots […]The post Unexpected square wave first appeared on John D. Cook.
Not quite going in circles
Sometimes you feel like you’re running around in circles, not making any progress, when you’re on the verge of a breakthrough. An illustration of this comes from integration by parts. A common example in calculus classes is to integrate ex sin(x) using integration by parts (IBP). After using IBP once, you get an integral similar […]The post Not quite going in circles first appeared on John D. Cook.
Transliterating Hebrew
Yesterday I wrote about cjhebrew, a LaTeX package that lets you insert Hebrew text by using a sort of transliteration scheme. That reminded me of unidecode, a Python package for transliterating Unicode to ASCII, that I wrote about before. I wondered how the two compare, and so this post will answer that question. Transliteration is […]The post Transliterating Hebrew first appeared on John D. Cook.
Permutable polynomials
Two polynomials p(x) and q(x) are said to be permutable if p(q(x)) = q(p(x)) for all x. It’s not hard to see that Chebyshev polynomials are permutable. First, Tn(x) = cos (n arccos(x)) where Tn is the nth Chebyshev polyomial. You can take this as a definition, or if you prefer another approach to defining […]The post Permutable polynomials first appeared on John D. Cook.
Including a little Hebrew in an English LaTeX document
I was looking up how to put a little Hebrew inside a LaTeX document and ran across a good answer on tex.stackexchange. Short answer: use the cjhebrew package. In a nutshell, you put your Hebrew text between \< and > using the cjhebrew package’s transliteration. You write left-to-right, and the text will appear right-to-left. For […]The post Including a little Hebrew in an English LaTeX document first appeared on John D. Cook.
All English vowel sounds in one sentence
Contrary to popular belief, English has more than five or ten vowel sounds. The actual number is disputed because of disagreements over when two sounds are sufficiently distinct to be classified as separate sounds. I’ve heard some people say 15, some 17, some over 20. I ran across a podcast episode recently that mentioned a […]The post All English vowel sounds in one sentence first appeared on John D. Cook.
Three notations by Iverson
The floor of y is the greatest integer less than or equal to y and is denoted ⌊y⌋. Similarly, the ceiling of y is the smallest integer greater than or equal to y and is denoted ⌈y⌉. Both of these notations were introduced by Kenneth Iverson. Before Iverson’s notation caught on, you might see [x] for […]The post Three notations by Iverson first appeared on John D. Cook.
Entering symbols in Emacs
Emacs has a relatively convenient way to add accents to letters or to insert a Unicode character if you know the code point for the value. See these notes. But usually you don’t know the Unicode values of symbols. Then what do you do? TeX commands You enter symbols by typing their corresponding TeX commands […]The post Entering symbols in Emacs first appeared on John D. Cook.
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) […]
...30313233343536373839...