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-04-26 03:16
Code katas taken more literally
Code katas are programming exercises intended to develop programming skills, analogous to the way katas develop martial art skills. But literal katas are choreographed. They are rituals rather than problem-solving exercises. There may be an element of problem solving, such as figuring how to better execute the prescribed movements, but katas are rehearsal rather than […]The post Code katas taken more literally first appeared on John D. Cook.
Seconds to hours
Suppose you have a number of seconds n and you want to convert it to hours and seconds. If you divide n by 3600, the quotient is the number of hours and the remainder is the number of seconds. For example, suppose n = 8072022. Here’s the obvious way to do the calculation in Python: […]The post Seconds to hours first appeared on John D. Cook.
Memorizing Planck’s constant with DALL-E
Planck’s constant used to be a measured quantity and now it is exact by definition. h = 6.62607015×10−34 J / Hz Rather than the kilogram being implicit in the units used to measure Planck’s constant, the mass of a kilogram is now defined to be whatever it has to be to make Planck’s constant have […]The post Memorizing Planck’s constant with DALL-E first appeared on John D. Cook.
DALL-E 2 and mnemonic images
I recently got an account for using OpenAI’s DALL-E 2 image generator. The example images I’ve seen are sorta surreal combinations of common words, and that made me think of the Major memory system. I’ve written about the Major system before. For example, I give an overview here and I describe how to use it […]The post DALL-E 2 and mnemonic images first appeared on John D. Cook.
Naming probability functions
Given a random variable X, you often want to compute the probability that X will take on a value less than x or greater than x. Define the functions FX(x) = Prob(X ≤ x) and GX(x) = Prob(X > x) What do you call F and G? I tend to call them the CDF (cumulative […]The post Naming probability functions first appeared on John D. Cook.
Floating point inverses and stability
Let f be a monotone, strictly convex function on a real interval I and let g be its inverse. For example, we could have f(x) = ex and g(x) = log x. Now suppose we round our results to N digits. That is, instead of working with f and g we actually work with fN […]The post Floating point inverses and stability first appeared on John D. Cook.
Inline computed content in org-mode
The previous post discussed how to use org-mode as a notebook. You can have blocks of code and blocks of results, analogous to cells in a Jupyter notebook. The code and the results export as obvious blocks when you export the org file to another format, such as LaTeX or HTML. And that’s fine for […]The post Inline computed content in org-mode first appeared on John D. Cook.
Org-mode as a lightweight notebook
You can think of org-mode as simply a kind of markdown, a plain text file that can be exported to fancier formats such as HTML or PDF. It’s a lot more than that, but that’s a reasonable place to start. Org-mode also integrates with source code. You can embed code in your file and have […]The post Org-mode as a lightweight notebook first appeared on John D. Cook.
Not so fast
James Gregory’s series for π is not so fast. It converges very slowly and so does not provide an efficient way to compute π. After summing half a million terms, we only get five correct decimal places. We can verify this with the following bc code. s = 0 scale = 50 for(k = 1; […]The post Not so fast first appeared on John D. Cook.
Complex AGM
The arithmetic-geometric mean (AGM) of two non-negative real numbers a and b is defined as the limit of the iteration starting with a0 = a and b0 = b and an+1 = ½ (an + bn) bn+1 = √(an bn) for n > 0. This sequence converges very quickly and is useful in numerical algorithms. […]The post Complex AGM first appeared on John D. Cook.
Galois theory without fields
My previous post described Galois connections, and how they generalize a pattern first recognized in the context of Galois theory. This pattern can extended far afield of its initial application to fields and their extensions. For example, you could take a random variable X and think of the pair consisting of its distribution function F: […]The post Galois theory without fields first appeared on John D. Cook.
Galois connections and Galois theory
What are Galois connections and what do they have to do with Galois theory? Galois connections are much more general than Galois theory, though Galois theory provided the first and most famous example of what we now call a Galois connection. Galois connections Galois connections are much more approachable than Galois theory. A Galois connection […]The post Galois connections and Galois theory first appeared on John D. Cook.
Helmholtz resonator revisited
We finished a bottle of wine this evening, and I blew across the top as I often do. (Don’t worry: I only do this at home. If we’re ever in a restaurant together, I won’t embarrass you by blowing across the neck of an empty bottle.) The pitch sounded lower than I expected, so I […]The post Helmholtz resonator revisited first appeared on John D. Cook.
Ratio test counterexample
Given a sequence a1, a2, a3, … let L be the limit of the ratio of consecutive terms: Then the series converges if L < 1 and diverges if L > 1. However, that’s not the full story. Here is an example from Ernesto Cesàro (1859–1906) that shows the ratio test to be more subtle […]The post Ratio test counterexample first appeared on John D. Cook.
Whittaker and Watson
Whittaker and Watson’s analysis textbook is a true classic. My only complaint about the book is that the typesetting is poor. I said years ago that I wish someone would redo the book in LaTeX and touch it up a bit. I found out while writing my previous post that in fact someone has done […]The post Whittaker and Watson first appeared on John D. Cook.
Keyhole contour integrals
The big idea The Cauchy integral theorem says that the integral of a function around a closed path in the complex plane depends only on the poles of the integrand inside the path. You can change the path itself however you like as long as you don’t change which poles are inside. This observation is […]The post Keyhole contour integrals first appeared on John D. Cook.
Galois diagram
The previous post listed three posts I’d written before about images on the covers of math books. This post is about the image on the first edition of Dummit and Foote’s Abstract Algebra. Here’s a version of the image on the cover I recreated using LaTeX. The image on the cover appears on page 495 […]The post Galois diagram first appeared on John D. Cook.
Book cover posts
When a math book has an intriguing image on the cover, it’s fun to get to the point in the book where the meaning of the image is explained. I have some ideas for book covers I’d like to write about, but here I’d like to point out three such posts I’ve already written. Weierstrass […]The post Book cover posts first appeared on John D. Cook.
Aristeia
When I had a long commute, I listened to everything I could get my hands on. That included a lot of Teaching Company courses from my local library. A couple of the courses I listened to were Elizabeth Vandiver lecturing on classics. One of the things I remember her talking about was aristeia, a character’s […]The post Aristeia first appeared on John D. Cook.
Gaussian elimination
When you solve systems of linear equations, you probably use Gaussian elimination, even if you don’t call it that. You may learn Gaussian elimination before you see it formalized in terms of matrices. So if you’ve had a course in linear algebra, and you sign up for a course in numerical linear algebra, it’s natural […]The post Gaussian elimination first appeared on John D. Cook.
Conway’s factoring trick
The numbers 152 through 156 have a lot of small prime factors. I’ll be more explicit about that shortly, but take my word for it for now. John Conway [1] took this simple observation and turned it into a technique for mentally factoring integers. Conway’s factoring method To look for factors of a number n, […]The post Conway’s factoring trick first appeared on John D. Cook.
Adding a tiny trap to stop chaos
The tent map is a famous example of a chaotic function. We will show how a tiny modification of the tent maps retains continuity of the function but prevents chaos. The tent map is the function f: [0, 1] → [0, 1] defined by This map has an unstable fixed point at x0 = 2/3. […]The post Adding a tiny trap to stop chaos first appeared on John D. Cook.
Ducci sequences
Pick four integers a, b, c, and d. Now iterate the procedure that takes these four integers to |b – a|, |c – b|, |d – c|, |a – d| You could think of the four integers being arranged clockwise in a circle, taking the absolute value of difference between each number and its neighbor […]The post Ducci sequences first appeared on John D. Cook.
Dijkstra extends Pythagoras
Suppose a triangle has sides a, b, and c. Label the angles opposite these three sides α, β, and γ respectively. Edsger Dijkstra published (EWD975) a note proving the following extension of the Pythagorean theorem: sgn(α + β – γ) = sgn(a² + b² – c²). Here the sgn function is -1, 0, or 1 […]The post Dijkstra extends Pythagoras first appeared on John D. Cook.
Phi Phi
I was reading something this afternoon and ran across φ(φ(m)) and thought that was unusual. I often run across φ(m), the number of positive integers less than m and relative prime to m, but don’t often see Euler’s phi function iterated. Application of φ∘φ This section will give an example of a theorem where φ(φ(m)) […]The post Phi Phi first appeared on John D. Cook.
Speculation on new SI prefixes
The SI prefixes giga and tera were adopted in 1960. The prefixes eta and peta were adopted in 1975, and zetta and yotta were adopted in 1991. Following this 15-year cadence, we should have adopted a few more prefixes by now. If we ever do introduce new prefixes, what might they be? The latest prefixes […]The post Speculation on new SI prefixes first appeared on John D. Cook.
NASA and conformal maps
A couple years ago I wrote about how NASA was interested in regions bounded by curves of the form For example, here’s a plot for A = 2, B = 1, α = 2.5 and β = 6. That post mentioned a technical report from NASA that explains why these shapes are important in application, […]The post NASA and conformal maps first appeared on John D. Cook.
Transformations of Olympic rings
The previous post gave the details of how Möbius transformations m(z) = (az + b)/(cz + d) transform circles. The image of a circle under a Möbius transformation is either a line or a circle, and in our examples the image will always be a circle. We start with an approximation of the Olympic rings […]The post Transformations of Olympic rings first appeared on John D. Cook.
Circles and lines under a Möbius transformation
This post will revisit a previous post in more detail. I’ve written before about how Möbius transformations map circles and lines to circles and lines. In this post I’d like to explore how you’d calculate which circle or line a given circle or line goes to. Given an equation of a line or circle, what […]The post Circles and lines under a Möbius transformation first appeared on John D. Cook.
Reciprocal of a circle
Let C be a circle in the complex plane with center c and radius r. Assume C does not pass through the origin. Let f(z) = 1/z. Then f(C) is also a circle. We will derive the center and radius of f(C) in this post. *** Our circle C is the set of points z satisfying […]The post Reciprocal of a circle first appeared on John D. Cook.
Computing zeta at even numbers
Last year I wrote several posts about computing ζ(3) where ζ is the Riemann zeta function. For example, this post. It happens that ζ can be evaluated in closed form at positive even arguments, but there’s still a lot of mystery about zeta at positive odd arguments. There’s a way to derive ζ(2n) using contour […]The post Computing zeta at even numbers first appeared on John D. Cook.
Constructive Picard
The previous post concerned the function h(z) = exp(-1/(1 – z² )). We said that the function is badly behaved near -1 and 1. How badly? The function has essential singularities at -1 and 1. This means that not only does h blow up near these points, it blows up spectacularly. Picard’s theorem says that […]The post Constructive Picard first appeared on John D. Cook.
No analytic bump
The word “smooth” in mathematics usually means infinitely differentiable. Occasionally the word is used to mean a function has as many derivatives as necessary, but without being specific about how many derivatives that is. A function is analytic if it has a convergent power series representation at every point of its domain. An analytic function […]The post No analytic bump first appeared on John D. Cook.
Bump functions
A bump function is a smooth (i.e. infinitely differentiable) function that is positive on some open interval (a, b) and zero outside that interval. I mentioned bump functions a few weeks ago and discussed how they could be used to prevent clicks in radio transmissions. Today I ran into a twitter thread that gave a […]The post Bump functions first appeared on John D. Cook.
The quality of an RNG depends on the application
A random number generator can be good for some purposes and not for others. This isn’t surprising given the fundamentally impossible task such generators are supposed to perform. Technically a random number generator is a pseudo random number generator because it cannot produce random numbers. But random is as random does, and for many purposes […]The post The quality of an RNG depends on the application first appeared on John D. Cook.
Numerically evaluating a theta function
Theta functions pop up throughout pure and applied mathematics. For example, they’re common in analytic number theory, and they’re solutions to the heat equation. Theta functions are analogous in some ways to trigonometric functions, and like trigonometric functions they satisfy a lot of identities. This post will comment briefly on an identity that makes a […]The post Numerically evaluating a theta function first appeared on John D. Cook.
Illegible work
When James Scott uses the word legible, he doesn’t refer to handwriting that is clear enough to read. He uses the word more broadly to mean something that is easy to classify, something that is bureaucrat-friendly. A thing is illegible if it is hard to pigeonhole. I first heard the term from Venkatesh Rao’s essay […]The post Illegible work first appeared on John D. Cook.
Length of periods in the (infinite) periodic table
A few days ago I wrote about what the periodic table would look like if we extended it, assuming the patterns that hold for known elements continue to hold. That post reported that the number of elements in nth period works out to There’s a simpler expression for Pn: Here ⌊x⌋ is the largest integer […]The post Length of periods in the (infinite) periodic table first appeared on John D. Cook.
Doubly periodic but not analytic
A sine wave is the canonical periodic function, so an obvious way to create a periodic function of two variables would be to multiply two sine waves: f(x, y) = sin(x) sin(y) This function is doubly periodic: periodic in the horizontal and vertical directions. Now suppose you want to construct a doubly periodic function of […]The post Doubly periodic but not analytic first appeared on John D. Cook.
Letter-like Unicode symbols
Unicode provides a way to distinguish symbols that look alike but have different meanings. We can illustrate this with the following Python code. import unicodedata as u for pair in [('K', 'K'), ('Ω', 'Ω'), ('ℵ', 'א')]: for c in pair: print(format(ord(c), '4X'), u.bidirectional(c), u.name(c)) This produces 4B L LATIN CAPITAL LETTER K 212A L KELVIN […]The post Letter-like Unicode symbols first appeared on John D. Cook.
Periodic table of abbreviations
I just updated my earlier post on chemical element abbreviations by adding a table to visualize the groupings, a sort of periodic table of element abbreviations. See that post for details. First letter First two letters First letter and next consonant Initials of first and second syllables Initials of first and third syllables First and […]The post Periodic table of abbreviations first appeared on John D. Cook.
Continued fractions as matrix products
Let pn / qn be the nth convergent of a continued fraction: Then Source: Julian Havil. The Irrationals. p. 212. Related posts Calendars and continued fractions Continued fractions of square roots Normal hazard continued fractionThe post Continued fractions as matrix products first appeared on John D. Cook.
Greek letter paradox
The Greek letter paradox is seeing the same symbol in two contexts and assuming it means the same thing. Maybe it’s used in many contexts, but I first heard it in the context of comparing statistical models. I used the phrase in my previous post, looking at α exp(5t) + β t exp(5t) and α […]The post Greek letter paradox first appeared on John D. Cook.
Double roots and ODEs
This post will resolve a sort of paradox. The process of solving a difference or differential equation is different when the characteristic equation has a double root. But intuitively there shouldn’t be much difference between having a double root and having two roots very close together. I’ll first say how double roots effect finding solutions […]The post Double roots and ODEs first appeared on John D. Cook.
Difference equations and differential equations
Difference equations are very much analogous to differential equations. Difference equations are more elementary, but differential equations are more familiar. It seems odd to use a more advanced thing to explain a simpler thing, like saying a quartet is a symphony orchestra with only four instruments. But if for some reason you managed to become […]The post Difference equations and differential equations first appeared on John D. Cook.
Generating functions for polynomial sequences
The previous post looked at a generating function for a specific polynomial sequence. This post will look at generating functions for polynomial sequences in general. (There’s an alternating term in the previous post that isn’t polynomial, but we’ll address that too.) The starting point for this post is a simple observation: If we let xD […]The post Generating functions for polynomial sequences first appeared on John D. Cook.
Generating noble gases
The previous post discussed what the periodic table would look like if it could be extended indefinitely and if certain patterns in the actual table continued to hold. In particular, the last element of each period would have atomic number and so we could call the Zn in the equation above noble numbers, atomic numbers […]The post Generating noble gases first appeared on John D. Cook.
Infinite periodic table
All the chemical elements discovered or created so far follow a regular pattern in how their electrons are arranged: the nth shell contains up to 2n – 1 suborbitals that each contain up to two electrons. For a given atomic number, you can determine how its electrons are distributed into shells and suborbitals using the […]The post Infinite periodic table first appeared on John D. Cook.
A footnote to year share
A couple weeks ago I wrote a post about the year share component of calculating the day of the week. To calculate the day of the week, you need to add the day of the week, a constant for the month, and the year share. Calculating year share is not that hard, but it’s the […]The post A footnote to year share first appeared on John D. Cook.
Inverse tetrahedral numbers
The previous post looked at the tetrahedral numbers: 1, 4, 10, 20, 35, … We could invert the process of creating tetrahedral numbers and ask for what n is a given number the nth tetrahedral number. So the inverse of 1 is 1, the inverse of 4 is 2, the inverse of 10 is etc. […]The post Inverse tetrahedral numbers first appeared on John D. Cook.
...15161718192021222324...