Sign up

John D. Cook

Not verified No WebSub updates No webmention support Valid

Applied Mathematics Consulting

Public lists
davewiner/hackerNewsStars
Fetched

John D. Cook
Text • John

Regular expression speed and error rates

Seven years ago I wrote a post about regular expressions to match diagnosis codes. I wanted to revisit that post looking at speed and error rates. Regular expressions usually do not exactly match what you’re looking for and nothing else. They have error false positives and false negatives. But they also have advantages, and context […]

The post Regular expression speed and error rates first appeared on John D. Cook.

John D. Cook Valid
Text • John

ICD-10 chapters and code letters

I’ve been thinking about ICD-10 codes; they come up a lot in my work. The ICD-10-CM standard is divided into 21 chapters, which generally correspond to the first letter of a code. However, a chapter may contain blocks beginning with more than one letter, and codes starting with a single letter, namely D, can span […]

The post ICD-10 chapters and code letters first appeared on John D. Cook.

John D. Cook Valid
Text • John

Posterior variance

A few days ago I wrote a post entitled Does additional data always reduce posterior variance?. In a nutshell, the answer is no, not always. That led the previous post which looked at posterior means for three Bayesian models, showing how the posterior mean is a weighted average of the prior mean and the mean […]

The post Posterior variance first appeared on John D. Cook.

John D. Cook Valid
Text • John

Posterior mean

Common sense says that what you believe after seeing new data should be some sort of compromise between what you believed before and what the new data says. You don’t want to ignore previous information or new information. How much should new data change your prior beliefs? When prior judgment and new information are in […]

The post Posterior mean first appeared on John D. Cook.

John D. Cook Valid
Text • John

Progress on Gilbreath’s conjecture

Years ago I wrote about Gilbreath’s conjecture. It’s a simple conjecture; you could explain it to anyone who understands what prime numbers are. See the linked post for a description of the problem. Gilbreath’s conjecture is simple, but it’s also kinda weird. As I wrote before, Paul Erdős speculated that Gilbreath’s conjecture is true but […]

The post Progress on Gilbreath’s conjecture first appeared on John D. Cook.

John D. Cook
Text • John

Reproducing a geometry theorem diagram

I ran across a geometry theorem with the following diagram. The theorem corresponding to the diagram is interesting, but I found reproducing the diagram more interesting. The segment AB is a diameter and the line CD is perpendicular to the diameter. Assume the outer circle is a unit circle. I guessed C = (cos(1), sin(1)) and made the […]

The post Reproducing a geometry theorem diagram first appeared on John D. Cook.

John D. Cook
Text • John

e approximation

I ran across the approximation e ≈ 2721/1001 recently. What makes this remarkable is its accuracy relative to the size of the denominator. You can create a trivial approximation just by truncating a decimal expansion e ≈ 2718/1000 but this is only good to four significant figures, but 2721/1001 is good to seven, almost eight, […]

The post e approximation first appeared on John D. Cook.

John D. Cook
Text • John

Does additional data always reduce posterior variance?

A discussion over lunch today brought up the fact that additional data does not always decrease the size of a confidence interval. This post will look at this from a Bayesian perspective. In general, new information reduces your uncertainty regarding whatever you’re estimating. The posterior distribution becomes more concentrated as more data are collected. That’s […]

The post Does additional data always reduce posterior variance? first appeared on John D. Cook.

John D. Cook Valid
Text • John

DNA Sequence Alignment and Kings

This morning I wrote a post that included the central Delannoy numbers. The nth central Delannoy number Dn counts the number of ways a king can move from one corner of a chessboard to the diagonally opposite corner without backtracking. The more general Delannoy numbers Dm,n are the analogy for an m × n rectangular board, not […]

The post DNA Sequence Alignment and Kings first appeared on John D. Cook.

John D. Cook Valid
Text • John

Distinguishing variables from parameters

Imagine the following dialog. Professor: f is a function of a real variable x that takes a real parameter k. Student: What’s a parameter? Professor: It’s a constant that can vary. Student: Then if it can vary, isn’t it a variable? Professor: Sorta, but no not really. This conversation plays out over and over, and unfortunately it often […]

The post Distinguishing variables from parameters first appeared on John D. Cook.

John D. Cook Valid
Text • John

Silver Rectangles and the Ways of Kings

Golden rectangles The defining property of golden rectangle is that if you stick a square on its longer side, you get another golden rectangle. The smaller vertical rectangle is similar to the larger horizontal rectangle. This means φ / 1 = (1 + φ) / φ which tells us φ² = 1 + φ and […]

The post Silver Rectangles and the Ways of Kings first appeared on John D. Cook.

John D. Cook Valid
Text • John

Derivative equals inverse

Here’s kind of a strange problem with an interesting solution: find a function f such that the derivative of f equals the inverse of f for all positive x. f ′(x) = f−1(x) This is a differential equation, but a very unusual one, one that cannot be solved using any of the techniques taught in a class on differential equations. […]

The post Derivative equals inverse first appeared on John D. Cook.

John D. Cook Valid
Text • John

Who you gonna believe: Grok or the docs?

The calculator utility bc has a minimal math library. For example, there’s no tangent function because you’re expected take the ratio of sine and cosine. (The Gnu version of bc does have a function for tangent, but the POSIX version does not.) And yet bc includes support for Bessel functions J(x). The bc function j […]

The post Who you gonna believe: Grok or the docs? first appeared on John D. Cook.

John D. Cook Valid
Text • John

Brace expansion tree

Here’s a crazy bash one-liner I found via an article by Peter Krumins: echo {w,t,}h{e{n{,ce{,forth}},re{,in,fore,with{,al}}},ither,at} This prints 30 English words: when, whence, whenceforth, where, wherein, wherefore, wherewith, wherewithal, whither, what, then, thence, thenceforth, there, therein, therefore, therewith, therewithal, thither, that, hen, hence, henceforth, here, herein, herefore, herewith, herewithal, hither, hat This post will explain how […]

The post Brace expansion tree first appeared on John D. Cook.

John D. Cook Valid
Text • John

When will the decimals in a/b repeat?

The previous post looked at how many digits are in the reduced fraction for the nth harmonic number. I was curious about how long the cycle of digits in a harmonic number might be. I wrote about the period length for the digits of fractions almost a decade ago. This post includes code so I can […]

The post When will the decimals in a/b repeat? first appeared on John D. Cook.

John D. Cook Valid
Text • John

Height of harmonic numbers

The previous post looked at writing the harmonic numbers as reduced fractions and estimating the number of digits in the numerator and denominator based on asymptotics. This is a follow up post with plots. We’ll choose our base b to be 2. And we’ll look at the total number of bits in both the numerator and […]

The post Height of harmonic numbers first appeared on John D. Cook.

John D. Cook Valid
Text • John

Writing down harmonic numbers

The nth harmonic number is the sum of the reciprocals of the first n positive integers. Hn = 1 + 1/2 + 1/3 + 1/4 + … + 1/n The product of all the denominators is n!, so you could write Hn as a fraction Hn = p/q where p = n! Hn is an integer and q = n!. While […]

The post Writing down harmonic numbers first appeared on John D. Cook.

John D. Cook
Text • John

Hart’s theorem

Hart’s theorem says If a triangle be formed by the arcs of three circles, the inscribed and the three escribed circles are all tangent to a new circle or line. Here “triangle” means a three-sided figure whose sides are portions of a circle. The inscribed circle is the largest circle that can fit inside the […]

The post Hart’s theorem first appeared on John D. Cook.

John D. Cook
Text • John

Incircles and Excircles of Pythagorean triangles

This post will reveal the connection between my two previous posts: one on the Star Trek lemma and one on Pythagorean triples. In the process of writing the latter, I looked at the Wikipedia article on Pythagorean triples and noticed this curious paragraph. In every Pythagorean triangle, the radius of the incircle and the radii of the […]

The post Incircles and Excircles of Pythagorean triangles first appeared on John D. Cook.

John D. Cook
Text • John

Consecutive Pythagorean triangle sides

In this post we find all Pythagorean triples that contain consecutive numbers, all Pythagorean triples (a, b, c) such that a + 1 = b or b + 1 = c. a + 1 = b George Osborne wrote a paper [1] addressing the question of when the squares of two consecutive numbers is also a square. Geometrically this is asking […]

The post Consecutive Pythagorean triangle sides first appeared on John D. Cook.

John D. Cook
Text • John

The Star Trek lemma

I was reading an article this evening and saw a footnote to a book by Arthur Baragar [1]. This caught my eye because he was my officemate at UT for a year. I found his book on Archive.org and was surprised to see “The Star Trek Lemma” in the table of contents. What could this […]

The post The Star Trek lemma first appeared on John D. Cook.

John D. Cook
Text • John

Regular expressions that work “everywhere”

The most frustrating aspect of regular expressions is that implementations vary. Features supported in one tool may not be supported at all in another tool, or they may be supported with slightly different syntax. I learned regular expressions in the context Perl, a maximalist regex environment. This led to frustration when features I expect to […]

The post Regular expressions that work “everywhere” first appeared on John D. Cook.

John D. Cook
Text • John

Lobachevsky’s integral formula

Let f be an even function with period π. Then the following remarkable theorem by Lobachevsky holds. This theorem is useful in Fourier analysis and signal processing. It’s useful to know even in the special case f(x) = 1. For a “jinc” analog, see this paper. *** Every time I see the name Lobachevsky I […]

The post Lobachevsky’s integral formula first appeared on John D. Cook.

John D. Cook Valid
Text • John

Queens on a prime order board

The n queens problem is to place on an n × n chessboard n queens so that none attacks any other. This means there is only one queen on every horizontal, vertical, and diagonal line. When n is a prime number ≥ 5, it is sufficient to place the queens on a line that has slope 2, 3, 4, …, […]

The post Queens on a prime order board first appeared on John D. Cook.

John D. Cook Valid
Text • John

All pieces on a 6 by 5 board

I’ve written a couple posts lately on getting an LLM to generate code to solve chess problems. The first used Claude to generate Prolog and the second used ChatGPT to generate Prolog. This post will use Claude to generate Z3/Python code. The puzzle is one I’ve written about before: Place all the pieces—king, queen, two […]

The post All pieces on a 6 by 5 board first appeared on John D. Cook.

John D. Cook
Text • John

Formalizing a ring theorem with Lean 4 and Claude

I’ve been testing Claude’s ability to generate Lean 4 code to prove theorems. I’ve written about a couple experiments that verified calculations. I did not write about my failed attempt to get Claude to formalize a proof of the pqr theorem for seminorms. This time I asked Claude to formally prove the theorem from the […]

The post Formalizing a ring theorem with Lean 4 and Claude first appeared on John D. Cook.

John D. Cook
Text • John

Partial fraction decomposition

Nearly everyone who has seen partial fraction decomposition was introduced to it as a way to compute integrals. If P(x) and Q(x) are polynomials, then you can break their ratio P(x)/Q(x) into a sum of terms that can each be integrated in closed form. As with most topics in a calculus class, partial fractions go by in […]

The post Partial fraction decomposition first appeared on John D. Cook.

John D. Cook
Text • John

Three examples suffice

You can’t prove a theorem by just checking a few examples. Except sometimes you can. A few weeks ago I wrote Pentagonal numbers are truncated triangular numbers. In a nutshell, if the pentagonal numbers are defined by Pn = (3n² − n)/2 and the triangular numbers by Tn = (n² + n)/2 then Pn = T2n − 1 − Tn − 1. Here’s a visualization […]

The post Three examples suffice first appeared on John D. Cook.

John D. Cook Valid
Text • John

Testing pentagonal numbers

The nth pentagonal number Pn is the number of dots in diagrams like those below with n concentric pentagons. We have the formula Pn = (3n² − n)/2 where n is a positive integer. If n is an integer but not positive, the equation above defines a generalized pentagonal number. If you’re given an n, you can easily compute Pn. […]

The post Testing pentagonal numbers first appeared on John D. Cook.

John D. Cook Valid
Text • John

Quaternion Rotations, Claude, and Lean

I got an email message this afternoon reporting a typo in a blog post from about a year ago on converting between quaternions and rotation matrices [1]. The email said exactly where the typo was, but I decided to see whether Claude would find it. Specifically, I prompted Sonnet 4.6 Medium with the following. Write […]

The post Quaternion Rotations, Claude, and Lean first appeared on John D. Cook.