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 03:01
Classroom exercise with networks
In the previous post I looked at graphs created from representing geographic regions with nodes and connecting nodes with edges if the corresponding regions share a border. It’s an interesting exercise to recover the geographic regions from the network. For example, take a look at the graph for the continental United States. It’s easy to […]The post Classroom exercise with networks first appeared on John D. Cook.
Adjacency networks
Suppose you want to color a map with no two bordering regions having the same color. If this is a map on a plane, you can do this using only four colors, but maybe you’d like to use more. You can reduce the problem to coloring the nodes in a graph. Each node corresponds to […]The post Adjacency networks first appeared on John D. Cook.
Shortest tours of Eurasia and Oceania
This is the final post in a series of three posts about shortest tours, solutions to the so-called traveling salesmen problem. The first was a tour of Africa. Actually two tours, one for the continent and one for islands. See this post for the Mathematica code used to create the tours. The second was about […]The post Shortest tours of Eurasia and Oceania first appeared on John D. Cook.
Three tours of the Americas
The previous post looked at an optimal tour of continental Africa. This post will give analogous tours of continental North America, North American Islands, and South America. The next post looks at Eurasia and Oceania. North American Continent Here’s the North American continental tour. The order of the tour is as follows. Canada United States […]The post Three tours of the Americas first appeared on John D. Cook.
A traveling salesman tour of Africa
Suppose you’d like to tour Africa, visiting each country once, then returning to your starting point, minimizing the distance traveled. Here’s my first attempt at a solution using Mathematica, based on an example in the documentation for FindShortestTour. africa = CountryData["Africa"] FindShortestTour[africa] GeoGraphics[{Thick, Red, GeoPath[africa[[%[[2]]]]]}] This produced the following map: Hmm. Maybe I should have […]The post A traveling salesman tour of Africa first appeared on John D. Cook.
Trig in hyperbolic geometry
I recently wrote posts about spherical analogs of the Pythagorean theorem, the law of cosines, and the law of sines. The corresponding formulas for hyperbolic space mostly just replace circular functions with hyperbolic functions, i.e. replace sine with hyperbolic sine and cosine with hyperbolic cosine. Triangles on a sphere or on a hyperbolic space like […]The post Trig in hyperbolic geometry first appeared on John D. Cook.
Eliminating a Bessel function branch cut
In an earlier post I looked in detail at a series for inverse cosine centered at 1. The function arccos(z) is multivalued in a neighborhood of 1, but the function arccos(z) / √(2 – 2z) is analytic in a neighborhood of 1. We cancel out the bad behavior of inverse cosine at 1 by dividing […]The post Eliminating a Bessel function branch cut first appeared on John D. Cook.
Branch cuts for elementary functions
As far as I know, all contemporary math libraries use the same branch cuts when extending elementary functions to the complex plane. It seems that the current conventions date back to Kahan’s paper [1]. I imagine to some extent he codified existing practice, but he also settled some issues, particularly regarding floating point implementation. I’ve […]The post Branch cuts for elementary functions first appeared on John D. Cook.
Series for inverse cosine at 1
Suppose you need to estimate the inverse cosine of an argument near 1. There’s a series for that: You can find this series, for example, here. This comes in handy, for example, when working with the analog of the Pythagorean theorem on a sphere. You could just use the series and be on your way. […]The post Series for inverse cosine at 1 first appeared on John D. Cook.
Literate programming to reduce errors
I had some errors in a recent blog post that might have been eliminated if I had programmatically generated the content of the post rather than writing it by hand. I rewrote the example in this post in using org-mode. My org file looked like this: #+begin_src python :session :exports none lax_lat = 33.94 lax_lon […]The post Literate programming to reduce errors first appeared on John D. Cook.
Computing VIN checksums
I’ve had to work a little with VIN numbers lately, and so I looked back at a post I wrote on the subject three years ago. That post goes into the details of Vehicle Identification Numbers and the quirky algorithm used to compute the check sum. This post captures the algorithm in Python code. See […]The post Computing VIN checksums first appeared on John D. Cook.
Square root mnemonics
Here’s a cute little poem: I wish I knew The root of two. O charmed was he To know root three. So we now strive To find root five. The beginning of each stanza is a mnemonic for the number mentioned in the following line. √ 2 = 1.414 √ 3 = 1.732 √ 5 […]The post Square root mnemonics first appeared on John D. Cook.
Runs of letters and digits in passwords
If a password of length n is made up of lower case letters and digits, with each symbol appearing with equal probability, how many times would you expect to shift between letters and digits when typing the password? If you’re typing the password on a mobile device, how many times would you change between alphabetic […]The post Runs of letters and digits in passwords first appeared on John D. Cook.
Modal logic posts
Blog posts about modal logic Typesetting modal logic Modal and temporal logic for security Word problems, modal logic, and regular expressions Axioms for S1 through S5 Naming and numbering modal logic systems Modal logic and science fiction Dual axioms Temporal and polymodal logics I created the image above by asking DALL-E 2 for an image […]The post Modal logic posts first appeared on John D. Cook.
Radius, circumference, and area in non-Euclidean geometry
How does the circumference of a circle vary with its radius? What about the area? The answers are simple and familiar in Euclidean geometry, but not as simple or as familiar in non-Euclidean geometry. This post will look at how circumference and area vary as a function of radius in three spaces: a surface with […]The post Radius, circumference, and area in non-Euclidean geometry first appeared on John D. Cook.
Unified Pythagorean Theorem
A few days ago I wrote that the spherical counterpart of the Pythagorean theorem is cos(c) = cos(a) cos(b) where sides a and b are measured in radians. If we’re on a sphere of radius R and we measure the sides in terms of arc length rather than in radians, the formula becomes cos(c/R) = […]The post Unified Pythagorean Theorem first appeared on John D. Cook.
Can Brownian motion do work?
According to the latest episode of Eclectic Tech, Richard Feynman argued that Brownian motion cannot do work, but researchers at the University of Arkansas have demonstrated that it can by generating an electric current from Brownian motion in a sheet of graphene. You can read more in the physics journal article by the researchers. Unfortunately […]The post Can Brownian motion do work? first appeared on John D. Cook.
Direction between two cities
This post is the third in a series of posts on spherical trigonometry. We first looked at the analog of the Pythagorean theorem on a sphere, then the analog of the law of cosines on a sphere. Now we look at the analog of the law of sines on a sphere. As before we denote […]The post Direction between two cities first appeared on John D. Cook.
Law of cosines on a sphere
The previous post looked at the analog of the Pythagorean theorem on a sphere. This post looks at the law of cosines on a sphere. Yesterday we looked at triangles on a sphere with sides a and b meeting at a right angle and hypotenuse c. Denote the angle opposite a side with the capital […]The post Law of cosines on a sphere first appeared on John D. Cook.
Pythagoras on a sphere
Suppose you drive a distance a, turn right, then drive a distance b. How far are you from where you started? If a and b are relatively small, then the answer is given by the Pythagorean theorem. Small here means small relative to the radius of the Earth. Any distance you drive is small enough: […]The post Pythagoras on a sphere first appeared on John D. Cook.
Chimera and sine of 60°
I was playing around with DALL-E last night. I pasted the definition of chimera into DALL-E and the results were bizarre. See this Twitter thread for images. I also played around with some more mnemonic images. Students often memorize the sines and cosines of 30°, 45°, and 60°. I thought about making a mnemonic image […]The post Chimera and sine of 60° first appeared on John D. Cook.
Cross platform muscle memory
I’ve mostly used Windows and Linux for the last several years. When I needed to get a new laptop recently I got a MacBook Pro. I’ve used a Mac before, but it’s been a while, and so I’m starting over. I can move between Windows and Linux and almost forget what OS I’m using because […]The post Cross platform muscle memory first appeared on John D. Cook.
More on near-integer decibels
In base 10, four decibel values are approximately integers. Yesterday I explored whether base 10 was unique in this regard. I defined the value of n decibels in base b to be g(n, b) = bn/b. Sticking in 10 for b gives the usual definition of decibel levels. There are two ways to quantify what […]The post More on near-integer decibels first appeared on John D. Cook.
Dump a pickle file to a readable text file
I got a data file from a client recently in “pickle” format. I happen to know that pickle is a binary format for serializing Python objects, but trying to open a pickle file could be a puzzle if you didn’t know this. Be careful There are a couple problems with using pickle files for data […]The post Dump a pickle file to a readable text file first appeared on John D. Cook.
Duodecibels
It’s a curious and convenient fact that many decibel values are close to integers [1]: 3 dB ≈ 2 6 dB ≈ 4 7 dB ≈ 5 9 dB ≈ 8 Is base 10 unique in this regard? If we were to look at the analogs of decibels in other bases, would we see a […]The post Duodecibels first appeared on John D. Cook.
Keeping data and code together with org-mode
With org-mode you can keep data, code, and documentation in one file. Suppose you have an org-mode file containing the following table. #+NAME: mydata | Drug | Patients | |------+----------| | X | 232 | | Y | 351 | | Z | 117 | Note that there cannot be a blank line between the […]The post Keeping data and code together with org-mode first appeared on John D. Cook.
YYZ and Morse code
The song YYZ by Rush opens with a theme based on the rhythm of “YYZ” in Morse code: -.-- -.-- --.. YYZ is the designation for the Toronto Pearson International Airport, the main airport serving Toronto. The idea for the song came from hearing the airport identifier in Morse code. However, the song puts no […]The post YYZ and Morse code first appeared on John D. Cook.
Twitter follower distribution
A conversation this morning prompted the question of how many Twitter accounts have between 10,000 and 20,000 followers. I hadn’t thought about the distribution numbers of followers in a while and was curious to revisit the topic. Apparently this question was more popular five years ago. When I did a few searches on the topic, […]The post Twitter follower distribution first appeared on John D. Cook.
Mahler’s inequality
I ran across a reference to Mahler the other day, not the composer Gustav Mahler but the mathematician Kurt Mahler, and looked into his work a little. A number of things have been named after Kurt Mahler, including Mahler’s inequality. Mahler’s inequality says the geometric mean of a sum bounds the sum of the geometric […]The post Mahler’s inequality first appeared on John D. Cook.
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.
...12131415161718192021...