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 2025-09-12 05:16
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 […]
QR Codes and Percolation
Percolation theory looks at problems such as the probability of being able to traverse some region with random obstacles. It is motivated by problems such as modeling the flow of a fluid in a porous medium. Here’s a percolation problem for QR codes: What is the probability that there is a path from one side […]
Why is an empty sum 0 and an empty product 1?
In response to my earlier post on why 0! should be 1, several people replied that 0! = 1 because an empty product is 1. You can define the factorial of an integer n as the product of all positive numbers less than or equal to n. There are no positive integers less than or equal […]
Quantifying uncertainty
The primary way to quantify uncertainty is to use probability. Subject to certain axioms that aim to capture common-sense rules for quantifying uncertainty, probability theory is essentially the only way. (This is Cox’s theorem.) Other methods, such as fuzzy logic, may be useful, though they must violate common sense (at least as defined by Cox’s theorem) […]
Defining zero factorial
Things are defined the way they are for good reasons. This seems blatantly obvious now, but it was eye-opening when I learned this my first year in college. Our professor, Mike Starbird, asked us to go home and think about how convergence of a series should be defined. Not how it is defined, but how […]
Why not statistics
Jordan Ellenberg’s parents were both statisticians. In his interview with Strongly Connected Components Jordan explains why he went into mathematics rather than statistics. I tried. I tried to learn some statistics actually when I was younger and it’s a beautiful subject. But at the time I think I found the shakiness of the philosophical underpinnings […]
Another reason we don’t apply the 80-20 rule
I’ve written about the 80-20 rule several times because it keeps coming up. I’d like to believe that each time I revisit it I understand it a little better. In its simplest form the 80-20 rule says 80% of your outputs come from 20% of your inputs. You might find that 80% of your revenue comes from 20% of […]
Endorsements
I’ve added a page for endorsements to my site. Thanks to everyone who let me use their photo and quote. If you’d like to contribute an endorsement, please contact me.
Magicians vs Repairmen
From The World Beyond Your Head: The appeal of magic is that it promises to render objects plastic to the will without one’s getting too entangled with them. Treated at arm’s length, the object can issue no challenge to the self. … The clearest contrast … that I can think of is the repairman, who […]
Looking ten years ahead
From Freeman Dyson: Economic forecasting is useful for predicting the future up to about ten years ahead. Beyond ten years the quantitative changes which the forecast accesses are usually sidetracked or made irrelevant by qualitative changes in the rules of the game. Qualitative changes are produced by human cleverness … or by human stupidity … Neither […]
...555657585960