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 10:02
How to make a chessboard in Excel
I needed to make an image of a chessboard for the next blog post, and I’m not very good at image editing, so I make one using Excel. There are Unicode characters for chess pieces— white king is U+2654, etc.—and so you can make a chessboard out of (Unicode) text. ♔♕♖♗♘♙♚♛♜♝♞♟ I placed the character […]The post How to make a chessboard in Excel first appeared on John D. Cook.
Initial letter frequency
I needed to know the frequencies of letters at the beginning of words for a project. The overall frequency of letters, wherever they appear in a word, is well known. Initial frequencies are not so common, so I did a little experiment. I downloaded the Canterbury Corpus and looked at the frequency of initial letters […]The post Initial letter frequency first appeared on John D. Cook.
Lake Wobegon Dice
Garrison Keillor’s fictional Lake Wobegon is a place “where all the children are above average.” Donald Knuth alluded to this in his exercise regarding “Lake Wobegon Dice,” a set of dice where the roll of each die is (probably) above average. Let A be a six-sided die with a 5 on one side and 3’s […]The post Lake Wobegon Dice first appeared on John D. Cook.
Index of coincidence
Index of coincidence is a statistic developed by William Friedman for use in cryptanalysis. It measures how unevenly symbols are distributed in a message. It’s a kind of signature that could be used, for example, to infer the language of a text, even if the text has been encrypted with a simple substitution cipher. It […]The post Index of coincidence first appeared on John D. Cook.
S and C functions
I was reading a book on orbital mechanics recently [1], and one of the things that stood out was the use of two variations on sine and cosine, functions the book denotes by S and C. Strictly speaking, the functions are defined to be the analytic continuation of the middle expressions to the full complex […]The post S and C functions first appeared on John D. Cook.
Offline documentation
It’s simpler to search the web than to search software-specific documentation. You can just type your query into a search engine and not have to be bothered by the differences in offline documentation systems for different software. But there are a couple disadvantages. First, the result may not be that relevant. For example, maybe you […]The post Offline documentation first appeared on John D. Cook.
Engineering attitude
Carver Mead on engineering: Engineering isn’t something you study and learny, and memorize, and know where to look up. Engineering is understanding things all the way to the bottom, no matter what field they are called, and being able use that to build stuff and make it work. I edited the quote slightly. Mead was […]The post Engineering attitude first appeared on John D. Cook.
Searching for pseudoprimes
I was reading a book on computer algebra and ran across an interesting theorem about Carmichael numbers in the one of the exercises. I’ll present that theorem below, but first I’ll back up and say what a pseudoprime is and what a Carmichael number is. Fermat’s theorem If p is a prime number, then for […]The post Searching for pseudoprimes first appeared on John D. Cook.
Finding computer algebra algorithms with computer algebra
I ran across an interesting footnote in Wolfram Koepf’s book Computer Algebra. Gosper’s algorithm [1] was probably the first algorithm which would not have been found without computer algebra. Gosper writes in his paper: “Without the support of MACSYMA and its developer, I could not have collected the experiences necessary to provoke the conjectures that […]The post Finding computer algebra algorithms with computer algebra first appeared on John D. Cook.
Approximate minimal bounding sphere
Problem statement Suppose you have a large number of points in 3D space and you want to find a sphere containing all the points. You’d like the sphere to be as small as possible, but you’re willing to accept a slightly larger sphere in exchange for simplicity or efficiency. False starts If you knew the […]The post Approximate minimal bounding sphere first appeared on John D. Cook.
Complex floor and a surprising pattern
The floor of a real number x, written ⌊x⌋, is the largest integer less than or equal to x. So, for example, ⌊π⌋ = 3 and ⌊-π⌋ = -4. The previous post applied the floor function to a complex number z. What does that mean? You can’t just say it’s the largest integer [1] less than z because the […]The post Complex floor and a surprising pattern first appeared on John D. Cook.
Plotting the Gauss map
A recent post looked at an example from one of Michael Trott’s tomes. This post looks at another example from the same tome. Trott made a contour plot of the Gauss map over the complex plane. I copied his code (almost) and reproduced his plot. ContourPlot[ Abs[1/(x + I y) - Floor[1/(x + I y)]], […]The post Plotting the Gauss map first appeared on John D. Cook.
Collatz analog in C
A few days ago I wrote about an analog of the Collatz conjecture for polynomials with coefficients mod m. When m = 2, the conjecture is true, but when m = 3 the conjecture is false. I wrote some Mathematica code on that post to work with polynomials as polynomials. Then a comment on that […]The post Collatz analog in C first appeared on John D. Cook.
3D bifurcation diagram
The following 2D bifurcation diagram is famous. You’ve probably seen it elsewhere. If you have seen it, you probably know that it has something to do with chaos, iterated functions, fractals, and all that. If you’d like to read in more detail about what exactly the plot means, see this post. I was reading Michael […]The post 3D bifurcation diagram first appeared on John D. Cook.
Where has all the productivity gone?
Balaji Srinivasan asks in a Twitter thread why we’re not far more productive given the technology available. Here I collect the five possible explanations he mentions. The Great Distraction. All the productivity we gained has been frittered away on equal-and-opposite distractions like social media, games, etc. The Great Dissipation. The productivity has been dissipated on […]The post Where has all the productivity gone? first appeared on John D. Cook.
Alt tags on tweet images
I learned this morning via a comment that Twitter supports alt text descriptions for images. I didn’t think that it did, and said that it didn’t, but someone kindly corrected me. When I post equations as images on this site, I always include the LaTeX source code in an alt tag. That way someone using […]The post Alt tags on tweet images first appeared on John D. Cook.
Nonlinear phase portrait
I was reading through Michael Trott’s Mathematica Guidebook for Programming and ran across the following plot. I find the image aesthetically interesting. I also find it interesting that the image is the phase portrait of a differential equation whose solution doesn’t look that interesting. That is, the plot of (x(t), x ‘(t)) is much more […]The post Nonlinear phase portrait first appeared on John D. Cook.
Polynomial analog of the Collatz conjecture
The Collatz conjecture, a.k.a. the 3n + 1 problem, a.k.a. the hailstone conjecture, asks whether the following sequence always terminates. Start with a positive integer n. If n is even, set n ← n /2. Otherwise n ← 3n + 1. If n = 1, stop. Otherwise go back to step 1. The Collatz conjecture […]The post Polynomial analog of the Collatz conjecture first appeared on John D. Cook.
Major memory system telephone keypad
This weekend I had to enter an alphabetic passcode on a numeric keypad. The keypad used the same letter-to-digit convention as a phone, but the letters were not printed on the keypad. That made me think about how much better the Major system is. I wondered what phone keypads would look like if they used […]The post Major memory system telephone keypad first appeared on John D. Cook.
Approximation error over unit disk
The previous post ended by plotting the error in approximating exp(x) with (2+x)/(2 – x): The error is much larger on the right end than the left. That made me wonder what the error might look like in the complex plane. Does the slice along real axis exhibit the minimum and maximum error, or are […]The post Approximation error over unit disk first appeared on John D. Cook.
Simple derivation of exponential approximation
I was watching one of Brian Douglas’ videos on control theory (Discrete Control #5) and ran into a simple derivation of an approximation I presented earlier. Back in April I wrote several post on simple approximations for log, exp, etc. In this post I gave an approximation for the exponential function: The control theory video […]The post Simple derivation of exponential approximation first appeared on John D. Cook.
Upper case, lower case, title case
Converting text to all upper case or all lower case is a fairly common task. One way to convert text to upper case would be to use the tr utility to replace the letters a through z with the letters A through Z. For example, $ echo Now is the time | tr '[a-z]' '[A-Z]' […]The post Upper case, lower case, title case first appeared on John D. Cook.
Continued fraction from entropy source testing
NIST publication 800-90B, Recommendations for the Entropy Sources Used for Random Bit Generation, contains an interesting continued fraction. Define a function where is the incomplete gamma function. NIST 800-90B gives [1] a continued fraction implement F, but the continued fraction includes a parameter k for no apparent reason. NIST cites a paper that in turn […]The post Continued fraction from entropy source testing first appeared on John D. Cook.
Removing Unicode formatting
Several people responded to my previous post asserting that screen readers would not be able to read text formatted via Unicode variants. Maybe some screen readers can’t handle this, but there’s no reason they couldn’t. Before I go any further, I’d like to repeat my disclaimer from the previous post: It’s a dirty hack, and […]The post Removing Unicode formatting first appeared on John D. Cook.
How to format text in Twitter
Twitter does not directly provide support for formatting text in bold, italic, etc. But it does support Unicode characters [1], and so a hack to get around the formatting limitation is to replace letters with Unicode variants. For example, you could tweet How to include bold or italic text in a tweet. I cheated in […]The post How to format text in Twitter first appeared on John D. Cook.
Predator-Prey period
The Lotka-Volterra equations are a system of nonlinear differential equations for modeling a predator-prey ecosystem. After a suitable change of units the equations can be written in the form where ab = 1. Here x(t) is the population of prey at time t and y(t) is the population of predators. For example, maybe x represents rabbits […]The post Predator-Prey period first appeared on John D. Cook.
Error estimates for splines with more boundary conditions
Yesterday I wrote about rates of convergence for natural cubic splines. This brief post reports similar results for more boundary conditions. As explained in the earlier post, a cubic spline that interpolates a function f at n+1 points satisfies 4n -2 equations in 4n variables. Two more equations are necessary to uniquely determine the interpolating […]The post Error estimates for splines with more boundary conditions first appeared on John D. Cook.
Random Fourier series
A theorem by Paley and Wiener says that a Fourier series with random coefficients produces Brownian motion on [0, 2π]. Specifically, produces Brownian motion on [0, 2π]. Here the Zs are standard normal (Gaussian) random variables. Here is a plot of 10 instances of this process. Here’s the Python code that produced the plots. import […]The post Random Fourier series first appeared on John D. Cook.
Rate of natural cubic spline convergence
Suppose you want to approximate a function with a polynomial by interpolating it at evenly spaced points. You might reasonably expect that the more points you use, the better the approximation will be. That might be true, but it might not. As explained here, for some functions the maximum approximation error actually increases as the […]The post Rate of natural cubic spline convergence first appeared on John D. Cook.
The fractal nature of Brownian motion
Yesterday I wrote about how to interpolate a Brownian path. If you’ve created a discrete Brownian path with a certain step size, you can go back and fill in at smaller steps as if you’d generated the values from the beginning. This means that instead of generating samples in order as a random walk, you […]The post The fractal nature of Brownian motion first appeared on John D. Cook.
Monotonic interpolation
Accuracy isn’t everything. Sometimes when you’re approximating a function you care more about matching a function’s qualitative behavior than matching its numerical values. One example is interpolating monotonic data. Say your data show that increasing input always increases output. It’s likely you want a function that interpolates your data to have the same property and […]The post Monotonic interpolation first appeared on John D. Cook.
Interpolating Brownian motion
Let W(t) be a standard Wiener process, a.k.a. a one-dimensional Brownian motion. We can produce a discrete realization of W by first setting W(0) = 0. Then let W(1) be a sample from a N(0, 1) random variable. Then let W(2) be W(1) plus another N(0, 1) sample. At each integer n > 0, W(n) […]The post Interpolating Brownian motion first appeared on John D. Cook.
Anything that starts with an integral sign
Ran across a fun quote this afternoon: There are in this world optimists who feel that any symbol that starts off with an integral sign must necessarily denote something that will have every property that they should like an integral to possess. This of course is quite annoying to us rigorous mathematicians; what is even […]The post Anything that starts with an integral sign first appeared on John D. Cook.
Technological boundary layer
The top sides of your ceiling fan blades are dusty because of a boundary layer effect. When the blades spin, a thin layer of air above the blades moves with the blades. That’s why the fan doesn’t throw off the dust. A mathematical model may have very different behavior in two large regions, with a […]The post Technological boundary layer first appeared on John D. Cook.
Mentally compute cosine
Ronald Doerfler presents a simple approximation for the cosine of an angle in degrees in his book Dead Reckoning. cos d° ≈ 1 – d(d + 1)/7000 The approximation is good to about three digits for angles between 0° and 40°. Although cosine is an even function, the approximation above is not, and the error […]The post Mentally compute cosine first appeared on John D. Cook.
Oscillatory differential equations
The solution to a differential equation is called oscillatory if its set of zeros is unbounded. This does not necessarily mean that the solution is periodic, but that it crosses the horizontal axis infinitely often. Fowler [1] studied the following differential equation by demonstrates both oscillatory and nonoscillatory behavior. x” + tσ |x|γ sgn x […]The post Oscillatory differential equations first appeared on John D. Cook.
Extending AGM to three variables
The AGM (arithmetic-geometric mean) is the limiting value you get when you take the arithmetic and geometric means of two numbers, then take the arithmetic and geometric means of the results, over and over. am = lambda x, y: (x + y)*0.5 gm = lambda x, y: (x * y)**0.5 def agm(x, y): while x […]The post Extending AGM to three variables first appeared on John D. Cook.
Average distance to the middle
The previous post looked at the average ℓp distance between points in the ℓp disk. This post looks at a related question, the average distance to the center. Unlike the previous post, we will look at dimension n greater than 2. The paper [1] cited earlier ends with this statement: It should be pointed out […]The post Average distance to the middle first appeared on John D. Cook.
Average lp distance in a disk
This post will define ℓp distance and look at the average ℓp distance between points in the ℓp unit disk. We will compute this distance by simulation. ℓp distance The ℓp distance between two points (x1, y1) and (x2, y2) is The ℓp unit disk is the points whose ℓp distance from the origin is […]The post Average lp distance in a disk first appeared on John D. Cook.
Complexity below the surface
The other day I ran across a Rick Beato video entitled “The most complex pop song of all time.” I thought the song would be something by a cerebral group like Rush, but instead it’s “Never Gonna Let You Go” by Sérgio Mendes. The song made it to #4 on the weekly pop charts in […]The post Complexity below the surface first appeared on John D. Cook.
Hebrew letters spotted in applied math
Math and physics use Greek letters constantly, but seldom do they use letters from any other alphabet. The only Cyrillic letter I recall seeing in math is sha (Ш, U+0428) for the so-called Dirc comb distribution. One Hebrew letter is commonly used in math, and that’s aleph (א, U+05D0). Aleph is used fairly often, but […]The post Hebrew letters spotted in applied math first appeared on John D. Cook.
Sum of independent but differently distributed variables
It’s well known that a binomial random variable can be approximated by a Poisson random variable, and under what circumstances the approximation is particularly good. See, for example, this post. A binomial random variable is the sum of iid (independent, identically distributed) Bernoulli random variables. But what if the Bernoulli random variables don’t have the […]The post Sum of independent but differently distributed variables first appeared on John D. Cook.
HAKMEM, AGM, and Pi
HAKMEM is a collection of tricks and trivia from the MIT AI lab written in 1972. I’ve mentioned HAKMEM here before. The image below came from HAKMEM item 123, explained here. I ran across HAKMEM item 143 while writing my previous two blog posts about the arithmetic-geometric mean (AGM). This entry, due to Gene Salamin, […]The post HAKMEM, AGM, and Pi first appeared on John D. Cook.
Computing logs with the AGM
In the previous post I said that Jonathan and Peter Borwein figured out how to use the rapid convergence of the AGM to compute various functions, including logarithms. This post will show how to compute logarithms using the AGM. First I need to define the Jacobi theta functions Note that if q is very small, […]The post Computing logs with the AGM first appeared on John D. Cook.
The magic AGM box
Suppose you are visited by aliens from halfway across the galaxy. After asking you a lot of questions, they give you a parting gift, little black boxes can compute x – x²/2 + x³/3 – … with unbelievable speed and accuracy. You say thank you and your visitors vanish. You get back home and wonder […]The post The magic AGM box first appeared on John D. Cook.
Reversed Cauchy-Schwarz inequality
This post will state a couple forms of the Cauchy-Schwarz inequality and then present the lesser-known reverse of the Cauchy-Schwarz inequality due to Pólya and Szegö. Cauchy-Schwarz inequality The summation form of the Cauchy-Schwarz inequality says that for sequences of real numbers xn and yn. The integral form of the Cauchy-Schwarz inequality says that for […]The post Reversed Cauchy-Schwarz inequality first appeared on John D. Cook.
My densest books
I recently got a copy of Methods of Theoretical Physics by Morse and Feshbach. It’s a dense book, literally and metaphorically. I wondered whether it might be the densest book I own, so I weighed some of my weightier books. Morse and Feshbach has density 1.005 g/cm³, denser than water. Gravitation by Misner, Thorne, and […]The post My densest books first appeared on John D. Cook.
Quaternion product as a matrix product
Pick a quaternion p = p0 + p1i + p2j + p3k and consider the function that acts on quaternions by multiplying them on the left by p. If we think of q as a vector in R4 then this is a linear function of q, and so it can be represented by multiplication by […]The post Quaternion product as a matrix product first appeared on John D. Cook.
Inner product from norm
If a vector space has an inner product, it has a norm: you can define the norm of a vector to be the square root of the inner product of the vector with itself. You can use the defining properties of an inner product to show that This is a form of the so-called polarization […]The post Inner product from norm first appeared on John D. Cook.
Email subscription switchover
I’ve used Feedburner to allow people to subscribe to this blog via email. That service is going away, and so I just moved everyone over to MailerLite. I turned off Feedburner email, so nobody should get duplicate email. Feedburner’s RSS service is still going, for now, but most RSS subscribers use my RSS feed without […]The post Email subscription switchover first appeared on John D. Cook.
...19202122232425262728...