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 15:17
Playing around with a rational rose
A “rose” in mathematics is typically a curve with polar equation r = cos(kθ) where k is a positive integer. If k is odd, the resulting graph has k “petals” and if k is even, the plot has 2k petals. Sometimes the term rose is generalized to the case of non-integer k. This is the […]The post Playing around with a rational rose first appeared on John D. Cook.
Quatrefoils
I was reading The 99% Invisible City this evening, and there was a section on quatrefoils. Here’s an example of a quatrefoil from Wikipedia. There’s no single shape known as a quatrefoil. It’s a family of shapes that look something like the figure above. I wondered how you might write a fairly simple mathematical equation […]The post Quatrefoils first appeared on John D. Cook.
Kronecker sum
I’m working on a project these days where I’ve used four different kinds of matrix product, which made me wonder if there’s another kind of product out there that I could find some use for. In the process of looking around for other matrix products, I ran across the Kronecker sum. I’ve seen Kronecker products […]The post Kronecker sum first appeared on John D. Cook.
Nonlinear mod 5
This post is a follow-on to the previous post on perfectly nonlinear functions. In that post we defined a way to measure the degree of nonlinearity of a function between two Abelian groups. We looked at functions that take sequences of four bits to a single bit. In formal terms, our groups were GF(24) and […]The post Nonlinear mod 5 first appeared on John D. Cook.
Perfectly nonlinear functions
The other day I heard someone suggest that a good cocktail party definition of cryptography is puzzle making. Cryptographers create puzzles that are easy to solve given the key, but ideally impossible without the key. Linearity is very useful in solving puzzles, and so a puzzle maker would like to create functions that are as […]The post Perfectly nonlinear functions first appeared on John D. Cook.
Python one-liner to print Roman numerals
Here’s an amusing little Python program to convert integers to Roman numerals: def roman(n): print(chr(0x215F + n)) It only works if n is between 1 and 12. That’s because Unicode contains characters for the Roman numerals I through XII. Here are the characters it produces: Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ Ⅶ Ⅷ Ⅸ Ⅹ […]The post Python one-liner to print Roman numerals first appeared on John D. Cook.
Bidirectional text
This post will take a look at simple bidirectional text, such as a bit of English inside an Arabic document, or a few words of Hebrew inside a French document. If you want to explore the subject in all its complexity, see Unicode Standard Annex 9. You may not need to do anything special to […]The post Bidirectional text first appeared on John D. Cook.
Understanding statistical error
A simple linear regression model has the form y = μ + βx + ε. This means that the output variable y is a linear function of the input variable x, plus some error term ε that is randomly distributed. There’s a common misunderstanding over whose error the error term is. A naive view is […]The post Understanding statistical error first appeared on John D. Cook.
Why a little knowledge is a dangerous thing
Alexander Pope famously said A little learning is a dangerous thing; Drink deep, or taste not the Pierian spring: There shallow draughts intoxicate the brain, And drinking largely sobers us again. I’ve been thinking lately about why a little knowledge is often a dangerous thing, and here’s what I’ve come to. Any complex system has […]The post Why a little knowledge is a dangerous thing first appeared on John D. Cook.
Expected value of X and 1/X
Yesterday I blogged about an exercise in the book The Cauchy-Schwarz Master Class. This post is about another exercise from that book, exercise 5.8, which is to prove Kantorovich’s inequality. Assume and for non-negative numbers pi. Then where is the arithmetic mean of m and M and is the geometric mean of m and M. […]The post Expected value of X and 1/X first appeared on John D. Cook.
The baseball inequality
There’s a theorem that’s often used and assumed to be true but rarely stated explicitly. I’m going to call it “the baseball inequality” for reasons I’ll get to shortly. Suppose you have two lists of k positive numbers each: and Then This says, for example, that the batting average of a baseball team is somewhere […]The post The baseball inequality first appeared on John D. Cook.
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.
...24252627282930313233...