About John D. Cook

I have decades of consulting experience helping companies solve complex problems involving applied math, statistics, and data privacy.

The RSS's url is : https://www.johndcook.com/blog/feed/

Please copy to your reader or subscribe it with :

Preview of RSS feed of John D. Cook

A “well-known” series

2024-05-22 09:25:09

I was reading an article [1] that refers to “a well-known trigonometric series” that I’d never seen before. This paper cites [2] which gives the series as Note that the right hand side is not a series in φ but rather in sin φ. Motivation Why might you know sin φ and want to calculate […]

The post A “well-known” series first appeared on John D. Cook.

Probability, cryptography, and naïveté

2024-05-21 09:36:28

Probability and cryptography have this in common: really smart people can be confidently wrong about both. I wrote years ago about how striking it was to see two senior professors arguing over an undergraduate probability exercise. As I commented in that post, “Professors might forget how to do a calculus problem, or make a mistake […]

The post Probability, cryptography, and naïveté first appeared on John D. Cook.

Thinking by playing around

2024-05-20 23:54:28

Richard Feynman’s Nobel Prize winning discoveries in quantum electrodynamics were partly inspired by his randomly observing a spinning dinner plate one day in the cafeteria. Paul Feyerabend said regarding science discovery, “The only principle that does not inhibit progress is: anything goes” (within relevant ethical constraints, of course). Ideas can come from anywhere, including physical […]

The post Thinking by playing around first appeared on John D. Cook.

Approximation by prime powers

2024-05-13 21:46:06

The well-known Weierstrass approximation theorem says that polynomials are dense in C [0, 1]. That is, given any continuous function f on the unit interval, and any ε > 0, you can find a polynomial P such that f and P are never more than ε apart. This means that linear combinations of the polynomials 1, […]

The post Approximation by prime powers first appeared on John D. Cook.

Logarithm approximation curiosity

2024-05-12 20:03:38

I’ve written before about three simple approximations for logarithms, for base 10 log10(x) ≈ (x – 1)/(x + 1) base e, loge(x) ≈ 2(x – 1)/(x + 1) and base 2 log2(x) ≈ 3(x – 1)/(x + 1). These can be used to mentally approximate logarithms to moderate accuracy, accurate enough for quick estimates. Here’s […]

The post Logarithm approximation curiosity first appeared on John D. Cook.

Iterated Mersenne primes

2024-05-12 02:06:32

A Mersenne number is a number of the form 2k − 1. A Mersenne prime is a Mersenne number which is also a prime. It turns out that if 2k − 1 is prime then k must be prime, so Mersenne numbers have the form 2p − 1 is prime. What about the converse? If […]

The post Iterated Mersenne primes first appeared on John D. Cook.

Small probabilities add, big ones don’t

2024-05-10 21:25:59

A video has been making the rounds in which a well-known professor [1] says that if something has a 20% probability of happening in one attempt, then it has a 40% chance of happening in two attempts, a 60% chance in happening in three attempts, etc. This is wrong, but it’s a common mistake. And […]

The post Small probabilities add, big ones don’t first appeared on John D. Cook.

Logistic regression quick takes

2024-05-08 20:17:50

This post is a series of quick thoughts related to logistic regression. It starts with this article on moving between logit and probability scales. *** Logistic regression models the probability of a yes/no event occurring. It gives you more information than a model that simply tries to classify yeses and nos. I advised a client […]

The post Logistic regression quick takes first appeared on John D. Cook.

Numerical application of mean value theorem

2024-05-08 02:07:28

Suppose you’d like to evaluate the function for small values of z, say z = 10−8. This example comes from [1]. The Python code from numpy import exp def f(z): return (exp(z) - 1 - z)/z**2 print(f(1e-8)) prints -0.607747099184471. Now suppose you suspect numerical difficulties and compute your result to 50 decimal places using bc […]

The post Numerical application of mean value theorem first appeared on John D. Cook.

Numerical differentiation with a complex step

2024-05-07 21:34:35

The most obvious way to approximate the derivative of a function numerically is to use the definition of derivative and stick in a small value of the step size h. f′ (x) ≈ ( f(x + h) − f(x) ) / h. How small should h be? Since the exact value of the derivative is the […]

The post Numerical differentiation with a complex step first appeared on John D. Cook.

MCMC and the coupon collector problem

2024-05-07 08:20:18

Bob Carpenter wrote today about how Markov chains cannot thoroughly cover high-dimensional spaces, and that they do not need to. That’s kinda the point of Monte Carlo integration. If you want systematic coverage, you can/must sample systematically, and that’s impractical in high dimensions. Bob gives the example that if you want to get one integration […]

The post MCMC and the coupon collector problem first appeared on John D. Cook.

Up and down the abstraction ladder

2024-05-04 20:58:00

It’s easier to go up a ladder than to come down, literally and metaphorically. Gian-Carlo Rota made a profound observation on the application of theory. One frequently notices, however, a wide gap between the bare statement of a principle and the skill required in recognizing that it applies to a particular problem. This isn’t quite […]

The post Up and down the abstraction ladder first appeared on John D. Cook.

Making documents with makefiles

2024-05-02 00:36:52

I learned to use the command line utility make in the context of building C programs. The program make reads an input file to tell it how to make things. To make a C program, you compile the source files into object files, then link the object files together. You can tell make what depends […]

The post Making documents with makefiles first appeared on John D. Cook.

Applied abstraction

2024-05-01 21:21:08

“Good general theory does not search for the maximum generality, but for the right generality.” — Saunders Mac Lane   One of the benefits of a scripting language like Python is that it gives you generalizations for free. For example, take the function sorted. If you give it a list of integers, it will return […]

The post Applied abstraction first appeared on John D. Cook.

A deck of cards

2024-04-30 21:16:39

One time when I was in grad school, I was a teaching assistant for a business math class that included calculus and a smattering of other topics, including a little bit of probability. I made up examples involving a deck of cards, but then learned to my surprise that not everyone was familiar with playing […]

The post A deck of cards first appeared on John D. Cook.

What can JWST see?

2024-04-28 21:02:08

The other day I ran across this photo of Saturn’s moon Titan taken by the James Webb Space Telescope (JWST). If JWST can see Titan with this kind of resolution, how well could it see Pluto or other planets? In this post I’ll do some back-of-the-envelope calculations, only considering the apparent size of objects, ignoring […]

The post What can JWST see? first appeared on John D. Cook.

Fizz buzz walk

2024-04-27 20:57:30

I ran across a graphic yesterday made by taking a sequence of steps of the same length, turning left on the nth step if n is prime, and otherwise continuing in the same direction. Here’s my recreation of the first 1000 steps: You can see that in general it makes a lot of turns at […]

The post Fizz buzz walk first appeared on John D. Cook.

Closed-form solutions to nonlinear PDEs

2024-04-25 19:21:38

The traditional approach to teaching differential equations is to present a collection of techniques for finding closed-form solutions to ordinary differential equations (ODEs). These techniques seem completely unrelated [1] and have arcane names such as integrating factors, exact equations, variation of parameters, etc. Students may reasonably come away from an introductory course with the false […]

The post Closed-form solutions to nonlinear PDEs first appeared on John D. Cook.

Choosing a Computer Language for a Project

2024-04-24 08:19:22

Julia. Scala. Lua. TypeScript. Haskell. Go. Dart. Various computer languages new and old are sometimes proposed as better alternatives to mainstream languages. But compared to mainstream choices like Python, C, C++ and Java (cf. Tiobe Index)—are they worth using? Certainly it depends a lot on the planned use: is it a one-off small project, or […]

The post Choosing a Computer Language for a Project first appeared on John D. Cook.

On greedy algorithms and rodeo clowns

2024-04-22 21:16:23

This weekend I ran across a blog post The Rodeo Clown Theory of Personal Development. The title comes from a hypothetical example of a goal you don’t know how to achieve: becoming a rodeo clown. Let’s say you decide you want to be a rodeo clown. And let’s say you’re me and you have no […]

The post On greedy algorithms and rodeo clowns first appeared on John D. Cook.

Finding strings in binary files

2024-04-20 23:54:28

There’s a little program called strings that searches for what appear to be strings inside binary file. I’ll refer to it as strings(1) to distinguish the program name from the common English word strings. [1] What does strings(1) consider to be a string? By default it is a sequence of four or more bytes that […]

The post Finding strings in binary files first appeared on John D. Cook.

Extract text from a PDF

2024-04-20 20:31:59

Arshad Khan left a comment on my post on the less and more utilities saying “on ubuntu if I do less on a pdf file, it shows me the text contents of the pdf.” Apparently this is an undocumented feature of GNU less. It works, but I don’t see anything about it in the man […]

The post Extract text from a PDF first appeared on John D. Cook.

Length of a general Archimedean spiral

2024-04-20 07:58:15

This post ties together the previous three posts. In this post, I said that an Archimedean spiral has the polar equation r = b θ1/n and applied this here to rolls of carpet. When n = 1, the length of the spiral for θ running from 0 to T is approximately ½ bT² with the […]

The post Length of a general Archimedean spiral first appeared on John D. Cook.

How big will a carpet be when you roll or unroll it?

2024-04-18 21:52:57

If you know the dimensions of a carpet, what will the dimensions be when you roll it up into a cylinder? If you know the dimensions of a rolled-up carpet, what will the dimensions be when you unroll it? This post answers both questions. Flexible carpet: solid cylinder The edge of a rolled-up carpet can […]

The post How big will a carpet be when you roll or unroll it? first appeared on John D. Cook.

Approximating a spiral by rings

2024-04-17 22:19:31

An Archimedean spiral has the polar equation r = b θ1/n This post will look at the case n = 1. I may look at more general values of n in a future post. (Update: See here.) The case n = 1 is the simplest case, and it’s the case I needed for the client […]

The post Approximating a spiral by rings first appeared on John D. Cook.

Hypergeometric function of a large negative argument

2024-04-17 09:00:07

It’s occasionally necessary to evaluate a hypergeometric function at a large negative argument. I was working on a project today that involved evaluating F(a, b; c; z) where z is a large negative number. The hypergeometric function F(a, b; c; z) is defined by a power series in z whose coefficients are functions of a, […]

The post Hypergeometric function of a large negative argument first appeared on John D. Cook.

More is less

2024-04-16 19:40:35

When I first started using Unix, I used a program called “more” to read files. The name makes sense because each time you press the space bar, more will show you more of your file, one screen at a time. Now everyone uses less, and more is all but forgotten. Daniel Halbert wrote more in […]

The post More is less first appeared on John D. Cook.

Precise answers to useless questions

2024-04-12 20:25:05

I recently ran across a tweet from Allen Downey saying So much of 20th century statistics was just a waste of time, computing precise answers to useless questions. He’s right. I taught mathematical statistics at GSBS [1, 2] several times, and each time I taught it I became more aware of how pointless some of […]

The post Precise answers to useless questions first appeared on John D. Cook.

Pairs in poker

2024-04-11 10:38:24

An article by Y. L. Cheung [1] gives reasons why poker is usually played with five cards. The author gives several reasons, but here I’ll just look at one reason: pairs don’t act like you might expect if you have more than five cards. In five-card poker, the more pairs the better. Better here means […]

The post Pairs in poker first appeared on John D. Cook.

Solar system means

2024-04-10 22:40:27

Yesterday I stumbled on the fact that the size of Jupiter is roughly the geometric mean between the sizes of Earth and the Sun. That’s not too surprising: in some sense (i.e. on a logarithmic scale) Jupiter is the middle sized object in our solar system. What I find more surprising is that a systematic […]

The post Solar system means first appeared on John D. Cook.