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-23 14:01
Julia for Python programmers
One of my clients is writing software in Julia so I’m picking up the language. I looked at Julia briefly when it first came out but haven’t used it for work. My memory of the language was that it was almost a dialect of Python. Now that I’m looking at it a little closer, I […]
Nicholas Higham on Mathematics in Color
This is reprint of Nick Higham’s post of the same title from the Princeton University Press blog, used with permission. Color is a fascinating subject. Important early contributions to our understanding of it came from physicists and mathematicians such as Newton, Young, Grassmann, Maxwell, and Helmholtz. Today, the science of color measurement and description is […]
Mixing Haskell and R
It would be hard to think of two programming languages more dissimilar than Haskell and R. Haskell was designed to enforce programming discipline; R was designed for interactive use. Haskell emphasizes correctness; R emphasizes convenience. Haskell emphasizes computer efficiency; R emphasizes interactive user efficiency. Haskell was written to be a proving ground for programming language theorists. R was written to be […]
The Fast Fourier Transform (FFT) and big data
The most direct way to compute a Fourier transform numerically takes O(n2) operations. The Fast Fourier Transform (FFT) can compute the same result in O(n log n) operations. If n is large, this can be a huge improvement. James Cooley and John Tukey (re)discovered the FFT in 1965. It was thought to be an original discovery […]
Generalization of Fibonacci ratios
Each Fibonacci number is the sum of its two predecessors. My previous post looked at generalizing this to the so-called Tribonacci numbers, each being the sum of its three predecessors. One could keep going, defining the Tetrabonacci numbers and in general the n-Fibonacci numbers for any n at least 2. For the definition to be complete, […]
Power method and Fibonacci numbers
Take an n × n matrix A and a vector x of length n. Now multiply x by A, then multiply the result by A, over and over again. The sequence of vectors generated by this process will converge to an eigenvector of A. (An eigenvector is a vector whose direction is unchanged when multiplied […]
Secret equation
I got a call this afternoon from someone who records audio books for the blind. He wanted to know the name of a symbol he didn’t recognize. He then asked me if the equation was real. Here’s the equation in context, from the book Michael Vey 4: Hunt for Jade Dragon. The context is as follows. Suddenly math […]
Juggling projects
Yesterday on Twitter I said I was thinking about writing the names of each of my clients and leads on balls so I could literally juggle them. I was only half joking. I didn’t write my clients and leads on balls, but I did write them on index cards. And it helped a great deal. It’s […]
Casting out sevens
A while back I wrote about a method to test whether a number is divisible by seven. I recently ran across another method for testing divisibility by 7 in Martin Gardner’s book The Unexpected Hanging and Other Mathematical Diversions. The method doesn’t save too much effort compared to simply dividing by 7, but it’s interesting. It looks […]
Computing square triangular numbers
The previous post stated a formula for f(n), the nth square triangular number (i.e. the nth triangular number that is also a square number): ((17 + 12√2)n + (17 – 12√2)n – 2)/32 Now 17 – 12√2 is 0.029… and so the term (17 – 12√2)n approaches zero very quickly as n increases. So the f(n) […]
When is a triangle a square?
Of course a triangle cannot be a square, but a triangular number can be a square number. A triangular number is the sum of the first so many positive integers. For example, 10 is a triangular number because it equals 1+2+3+4. These numbers are called triangle numbers because you can form a triangle by having a row of […]
Basics equations of beam deflection
In the preface to his book Strength of Materials, J. P. Den Hartog says After the alphabet and the tables of multiplication, nothing has proved quite so useful in my professional life as these six little expressions. The six expressions he refers to are nicknamed the vergeet-me-nietjes in Dutch, which translates to forget-me-nots in English. They are also known […]
Deserted island books
You’ve probably heard someone ask someone else what books they would take to a deserted island. It’s usually implied that you’re bringing books for pleasure, not books that would help you survive on the island or leave it. People often answer the question with a list of their favorite books, perhaps skewed in favor of long […]
Attributing changes to numerator and denominator
This afternoon I helped someone debug a financial spreadsheet. One of the reasons spreadsheets can be so frustrating to work with is that assumptions are hard to see. You have to click on cells one at a time to find formulas, then decode cell coordinates into their meanings. The root problem turned out to be […]
Effective Computation in Physics
Earlier this week I had a chance to talk with Anthony Scopatz and Katy Huff about their new book, Effective Computation in Physics. JC: Thanks for giving me a copy of the book when we were at SciPy 2015. It’s a nice book. It’s about a lot more than computational physics. KH: Right. If you think of […]
Last digit of largest known prime
In my previous post, we looked at the largest known prime, P = 257885161 – 1, and how many digits it has in various bases. This post looks at how to find the last digit of P in base b. We assume b < P. (If b = P then the last digit is 0, and if […]
Playing with the largest known prime
The largest known prime at the moment is P = 257885161 – 1. This means that in binary, the number is a string of 57,885,161 ones. You can convert binary numbers to other bases that are powers of two, say 2k, by starting at the right end and converting to the new base in blocks of […]
Last digits of Fibonacci numbers
If you write out a sequence of Fibonacci numbers, you can see that the last digits repeat every 60 numbers. The 61st Fibonacci number is 2504730781961. The 62nd is 4052739537881. Since these end in 1 and 1, the 63rd Fibonacci number must end in 2, etc. and so the pattern starts over. It’s not obvious that the cycle […]
The Monosyllabic Raven
David Morice rewrote Edgar Allen Poe’s poem The Raven in words of one syllable. Here is the first stanza: Once at twelve on one night’s drear, ’twas while I, weak and tired thought here On the words in lots of quaint and odd old tomes of mind’s lost lore, While I dozed, so near a nap, there […]
The success of OOP
Allen Wirft-Brock gave the following defense of OOP a few days ago in a series of six posts on Twitter: A young developer approached me after a conf talk and said, “You must feel really bad about the failure of object-oriented programming.” I was confused. I said, “What do you mean that object-orient programming was […]
Life lessons from differential equations
Ten life lessons from differential equations: Some problems simply have no solution. Some problems have no simple solution. Some problems have many solutions. Determining that a solution exists may be half the work of finding it. Solutions that work well locally may blow up when extended too far. Boundary conditions are the hard part. Something […]
Numerators of harmonic numbers
Harmonic numbers The nth harmonic number, Hn, is the sum of the reciprocals of the integers up to and including n. For example, H4 = 1 + 1/2 + 1/3 + 1/4 = 25/12. Here’s a curious fact about harmonic numbers, known as Wolstenholme’s theorem: For a prime p > 3, the numerator of Hp-1 […]
High-dimensional integration
Numerically integrating functions of many variables almost always requires Monte Carlo integration or some variation. Numerical analysis textbooks often emphasize one-dimensional integration and, almost as a footnote, say that you can use a product scheme to bootstrap one-dimensional methods to higher dimensions. True, but impractical. Traditional numerical integration routines work well in low dimensions. (“Low” […]
Wolfram obeys Zawinksi’s law
Zawinski’s law of software development: Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can. The folks behind Mathematica and Wolfram Alpha announced yesterday now they too can read email.
Scientific computing in Python
Scientific computing in Python is expanding and maturing rapidly. Last week at the SciPy 2015 conference there were about twice as many people as when I’d last gone to the conference in 2013. You can get some idea of the rapid develop of the scientific Python stack and its future direction by watching the final […]
Contact info diagram
My contact information arranged into a diagram: Yesterday at SciPy 2015 Allen Downey did something similar for his contact info and gave me the idea for the image above. LinkedIn doesn’t quite fit; you have to know that LinkedIn profiles stick linkedin.com/in/ before the user name.
Multiple choice
A certain question has the following possible answers. All of the below None of the below All of the above One of the above None of the above None of the above Which answer is correct? Source
When the last digits of powers don’t change
If you raise any integer to the fifth power, its last digit doesn’t change. For example, 25 = 32. It’s easy to prove this assertion by brute force. Since the last digit of bn only depends on the last digit of b, it’s enough to verify that the statement above holds for 0, 1, 2, […]
No, I’m not a bot.
Periodically someone on Twitter will suggest that one of my Twitter accounts is a bot. Others will reply in the second person plural, suggesting that there’s a group of people behind one of the accounts. These accounts aren’t run by a bot or a committee, just me. I do use software to schedule my tweets […]
The name we give to bright ideas
From The Book of Strange New Things: … I said that if science could come up with something like the Jump it could surely solve a problem like that. Severin seized hold of that word, “science.” Science, he said, is not some mysterious larger-than-life force, it’s just the name we give to bright ideas that […]
Algorithmic wizardry
Last week I wrote a short commentary on James Hague’s blog post Organization skills beat algorithmic wizardry. This week that post got more traffic than my server could handle. I believe it struck a chord with experienced software developers who know that the challenges they face now are not like the challenges they prepared for in school. Although […]
The Nickel Tour
If you’re new to this blog, welcome! Let me show you around. Here are some of the most popular posts on this site and some other things I’ve written. If you’d like to subscribe to this site you can do so by RSS or email. I also have a monthly newsletter. You can find out more about me and my background here. […]
The most important skill in software development
Here’s an insightful paragraph from James Hague’s blog post Organization skills beat algorithmic wizardry: When it comes to writing code, the number one most important skill is how to keep a tangle of features from collapsing under the weight of its own complexity. I’ve worked on large telecommunications systems, console games, blogging software, a bunch […]
AI Spring
Artificial intelligence, or at least the perception of artificial intelligence, has gone from disappointing to frightening in the blink of an eye. As Marc Andreessen said on Twitter this morning: AI: From “It’s so horrible how little progress has been made” to “It’s so horrible how much progress has been made” in one step. When […]
Ursula K. Le Guin has it backward
Ursula K. Le Guin is asking people to not buy books from Amazon because they market bestsellers, the literary equivalent of junk food. She said last week I believe that reading only packaged microwavable fiction ruins the taste, destabilizes the moral blood pressure, and makes the mind obese. I agree with that. That’s why I shop […]
Reading equations forward and backward
There is no logical difference between writing A = B and writing B = A, but there is a psychological difference. Equations are typically applied left to right. When you write A = B you imply that it may be useful to replace A with B. This is helpful to keep in mind when learning something […]
Launching missiles with Haskell
Haskell advocates are fond of saying that a Haskell function cannot launch missiles without you knowing it. Pure functions have no side effects, so they can only do what they purport to do. In a language that does not enforce functional purity, calling a function could have arbitrary side effects, including launching missiles. But this […]
Mystery curve
This afternoon I got a review copy of the book Creating Symmetry: The Artful Mathematics of Wallpaper Patterns. Here’s a striking curves from near the beginning of the book, one that the author calls the “mystery curve.” The curve is the plot of exp(it) – exp(6it)/2 + i exp(-14it)/3 with t running from 0 to 2π. Here’s Python […]
RSS feeds for categories
You can subscribe to this blog using this RSS feed. If you would like to only subscribe to posts in certain categories, you can do so using the category-specific feeds below. Business Clinical trials Computing Creativity Graphics Machine learning Math Music Python Science Software development Statistics Typography Misc You can also subscribe to my Twitter […]
Unix-like shells on Windows
This post gives some notes on ways to create a Unix-like command line experience on Windows, without using a virtual machine like VMWare or a quasi-virtual machine like Cygwin. Finding Windows ports of Unix utilities is easy. The harder part is finding a shell that behaves as expected. (Of course “as expected” depends on your expectations!) There […]
Data, code, and regulation
Data is code and code is data. The distinction between software (“code”) and input (“data”) is blurry at best, arbitrary at worst. And this distinction, or lack thereof, has interesting implications for regulation. In some contexts software is regulated but data is not, or at least software comes under different regulations than data. For example, […]
Subway map of the solar system
This is a thumbnail version of a large, high-resolution image by Ulysse Carion. Thanks to Aleksey Shipilëv (@shipilev) for pointing it out. It’s hard to see in the thumbnail, but the map gives the change in velocity needed at each branch point. You can find the full 2239 x 2725 pixel image here or click on the […]
Fibonacci number system
Every positive integer can be written as the sum of distinct Fibonacci numbers. For example, 10 = 8 + 2, the sum of the fifth Fibonacci number and the second. This decomposition is unique if you impose the extra requirement that consecutive Fibonacci numbers are not allowed. [1] It’s easy to see that the rule against consecutive […]
New monthly newsletter
Thank you for reading my blog. I’m starting a new email newsletter to address two things that readers have mentioned. Some say they enjoy the blog, but I post more often than they care to keep up with, particularly if they’re only interested in the non-technical posts. Others have said they’d like to know more about […]
Information hiding
One of the basic principles of software development is information hiding. People agree that it’s desirable, but may not realize they have different ideas of what it means. And when done poorly, well-meaning attempts to make software more maintainable backfire. Leo Brodie cautions … we should clarify. From what, or whom, are we hiding information? […]
Rotating PDF pages with Python
Yesterday I got a review copy of Automate the Boring Stuff with Python. It explains, among other things, how to manipulate PDFs from Python. This morning I needed to rotate some pages in a PDF, so I decided to try out the method in the book. The sample code uses PyPDF2. I’m using Conda for […]
RSS feeds for Twitter accounts
Twitter once provided RSS feeds for all Twitter accounts. They no longer provide this service. However, third parties can create RSS feeds from the content of Twitter accounts. BazQux has done this for my daily tip accounts, so you can subscribe to any of my accounts via RSS using the feeds linked to below. AlgebraFact AnalysisFact […]
Scientifically valid, practically invalid
In a recent episode of EconTalk, Phil Rosenzweig describes how the artificial conditions necessary to make experiments scientifically valid can also make the results practically invalid. Rosenzweig discusses experiments designed to study decision making. In order to make clean comparisons, subjects are presented with discrete choices over which they have no control. They cannot look for […]
The Mozart Myth
I don’t know how many times I’ve heard about how Mozart would compose entire musical scores in his head and only write them down once they were finished. Even authors who stress that creativity requires false starts and hard work have said that Mozart may have been an exception. But maybe he wasn’t. In his new book How to […]
Pedantic arithmetic rules
Generations of math teachers have drilled into their students that they must reduce fractions. That serves some purpose in the early years, but somewhere along the way students need to learn reducing fractions is not only unnecessary, but can be bad for communication. For example, if the fraction 45/365 comes up in the discussion of […]
...495051525354