John D. Cook Consulting Blog
by John
1d ago
I typically announce new blog posts from my most relevant twitter account: data science from @DataSciFact, algebra and miscellaneous math from @AlgebraFact, TeX and typography from @TeXtip, etc. If you’d like to be sure that you’re notified of each post, regardless of what algorithms Twitter applies to your feed, you can subscribe to this blog via or RSS. If you subscribe via email you’ll see each post in your RSS stream as it is published. If you subscribe by email you’ll get one email each day around 11:00 AM Central Time. You can also get an email once a month with highlights from the blog ..read more
John D. Cook Consulting Blog
by John
3d ago
When I think of bit twiddling, I think of C. So I was surprised to read Paul Khuong saying he thinks of Common Lisp (“CL”). As always when working with bits, I first doodled in SLIME/SBCL: CL’s bit manipulation functions are more expressive than C’s, and a REPL helps exploration. I would not have thought of Common Lisp being more expressive for bit manipulation than C, though in hindsight perhaps I should have. Common Lisp is a huge language, and a lot of thought went into it. It’s a good bet that if CL supports something it supports it well. One of the functions Khoung uses is integer-lengt ..read more
John D. Cook Consulting Blog
by John
3d ago
The lemniscate of Bernoulli came up in a post a few days ago. This shape is a special case of a Cassini oval: ((x + a)² + y²) ((x – a)² + y²) = a4. Here’s another way to arrive at the lemniscate. Draw a hyperbola (blue in the figure below), then draw circles centered at points on the hyperbola and passing through the center of the hyperbola. The figure-eight that is traced out in the middle is a lemniscate. The post Lemniscate of Bernoulli first appeared on John D. Cook ..read more
John D. Cook Consulting Blog
by John
4d ago
Van Aubel’s theorem is analogous to Napoleon’s theorem, though not a direct generalization of it. Napoleon’s theorem says to start with any triangle and draw equilateral triangles on each side. Connect the centers of the three new triangles, and you get an equilateral triangle. Now suppose you start with a quadrilateral and draw squares on each side. Connect the centers of the squares. Do you get a square? No, but you do get something interesting. Van Aubel’s theorem says that if you connect the centers of squares on opposite faces of the quadrilateral (dashed lines below), the two line segme ..read more
John D. Cook Consulting Blog
by John
4d ago
Can a Pythagorean triangle have one size of length 2023? Yes, one possibility is a triangle with sides (2023, 6936, 7225). Where did that come from? And can we be more systematic, listing all Pythagorean triangles with a side of length 2023? Euclid’s formula generates Pythagorean triples by sticking integers m and n into the formula (m² – n², 2mn, m² + n²). If one of these three numbers equals 2023, it’s going to have to be the first one. Why? The second number is even, and 2023 is odd, so that one is ruled out. It’s less obvious but true that the hypotenuse m² + n² cannot be 2023. We could v ..read more
John D. Cook Consulting Blog
by John
5d ago
The density function of a normal distribution with mean 0 and standard deviation √(2kt) satisfies the heat equation. That is, the function satisfies the partial differential equation You could verify this by hand, or if you’d like, here’s Mathematica code to do it. u[x_, t_] := PDF[NormalDistribution[0, Sqrt[2 k t]], x] Simplify[ D[u[x, t], {t, 1}] - k D[u[x, t], {x, 2}] ] This returns 0 as expected. Solutions to the heat equation are unique if we specify initial conditions. So if we start with a very concentrated heat source at time t = ε, say where ε is a tiny but positive n ..read more
John D. Cook Consulting Blog
by John
6d ago
Here’s something surprising: You can apply a symmetric function to a symmetric shape and get something out that is not symmetric. Let f(z) be the average of z and its reciprocal: f(z) = (z + 1/z)/2. This function is symmetric in that it sends z and 1/z to the same value. It’s also symmetric in the sense that it is its own inverse, i.e. f(f(z)) = z. Now apply f to circles in the complex plane, varying the center and the radius. Here are some examples of what the image of circles are. These shapes look a lot like a cross section of an airplane wing, i.e.an airfoil. You can vary the radius of th ..read more
John D. Cook Consulting Blog
by John
1w ago
Johannes Kepler thought that planetary orbits were ellipses. Giovanni Cassini thought they were ovals. Kepler was right, but Cassini wasn’t far off. In everyday speech, people use the words ellipse and oval interchangeably. But in mathematics these terms are distinct. There is one definition of an ellipse, and several definitions of an oval. To be precise, you have to say what kind of oval you have in mind, and in the context of this post by oval I will always mean a Cassini oval. Ellipses and ovals each have two foci, f1 and f2. Let d1(p) and d2(p) be the distances from a point p to each of t ..read more
John D. Cook Consulting Blog
by John
1w ago
An ellipse can be defined as the set of points such that the sum of the distances to two fixed points, the foci, has a constant value. A Cassini oval is the set of points such that the product of the distances to two foci has a constant value. You can write down an equation for a Cassini oval for given parameters a and b as ((x + a)² + y²) ((x – a)² + y²) = b². For some reason, references almost always plot Cassini ovals by fixing a and letting b vary. When we set a = 1 and let b = 0.5, 1, 1.5, …, 5 this produces the following plot. But you could also fix b and let a vary. Here’s what we get ..read more
John D. Cook Consulting Blog
by John
1w ago
In the process of creating a Pratt certificate to prove that a number n is prime, you have to find a number a that seems kinda arbitrary. As we discussed here, a number n is prime if there exists a number a such that an-1 = 1 mod n and a(n-1)/p ≠ 1 mod n for all primes p that divide n – 1. How do you find a? You try something and see if it works. If it doesn’t, you try again. How many values of a might you have to try? Could this take a long time? You need to pick 2 ≤ a ≤ n – 2, and there are φ(n-1) values of a that will work. Here φ is Euler’s totient function. So the probability of pick ..read more

OR