Latest posts
- Reproducing a geometry theorem diagramJul 06, 2026John
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 […] Reproducing a geometry theorem diagram first appeared on Joh
- e approximationJul 06, 2026John
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, […] e approximation first appeared on John D. Cook.
- Does additional data always reduce posterior variance?Jul 04, 2026John
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 […] Does additional data always r
- DNA Sequence Alignment and KingsJul 01, 2026John
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 […] DNA Sequence Alignment and Kings first appeared on John D. Cook.
- Distinguishing variables from parametersJun 30, 2026John
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 […] Distinguishing variables from parameters first appeared on
- Silver Rectangles and the Ways of KingsJun 30, 2026John
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 […] Silver Rectangles and the Ways of Kings first appeared on John D. Cook.
- Derivative equals inverseJun 30, 2026John
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. […] Derivative equals inverse first appeared on John D. Cook.
- Who you gonna believe: Grok or the docs?Jun 29, 2026John
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 […] Who you gonna believe: Grok or the docs? first appeared on John D. Cook.
- Brace expansion treeJun 28, 2026John
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, h
- When will the decimals in a/b repeat?Jun 27, 2026John
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 […] When will the decimals in a/b repeat? first appeared on John D. Cook.
- Height of harmonic numbersJun 27, 2026John
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 […] Height of harmonic numbers first appeared on John D. Cook.
- Writing down harmonic numbersJun 27, 2026John
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 […] Writing down harmonic numbers first appeared on John D. Cook.
- Hart’s theoremJun 25, 2026John
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 […] Hart’s theorem first appeared on John D. Cook.
- Incircles and Excircles of Pythagorean trianglesJun 25, 2026John
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 […] Incircles and Excircles of Pythagorean triangles first appe
- Consecutive Pythagorean triangle sidesJun 25, 2026John
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 […] Consecutive Pythagorean triangle sides first appeared on John D. Cook.
- The Star Trek lemmaJun 25, 2026John
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 Star Trek lemma first appeared on John D. Cook.
- Regular expressions that work “everywhere”Jun 24, 2026John
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 […] Regular expressions that work “everywhere” first
- Lobachevsky’s integral formulaJun 22, 2026John
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 […] Lobachevsky’s integral formula first appeared on John D. Cook.
- Queens on a prime order boardJun 22, 2026John
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, …, […] Queens on a prime order board first appeared on John D. Cook.
- All pieces on a 6 by 5 boardJun 20, 2026John
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 […] All pieces on a 6 by 5 board first appeared on John D. Cook.
- Formalizing a ring theorem with Lean 4 and ClaudeJun 17, 2026John
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 […] Formalizing a ring theorem with Lean 4 and Claude first appeared on John D. C
- Partial fraction decompositionJun 16, 2026John
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 […] Partial fraction decomposition first appeared on John D. Cook.
- Three examples sufficeJun 16, 2026John
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 […] Three examples suffice first appeared on John D. Cook.
- Testing pentagonal numbersJun 15, 2026John
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. […] Testing pentagonal numbers first appeared on John D. Cook.
- Quaternion Rotations, Claude, and LeanJun 15, 2026John
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 […] Quaternion Rotations, Claude, and Lean first appeared on John D. Cook.
- Writing Prolog with ChatGPTJun 15, 2026John
A few days ago I wrote about using Claude to solve a chess puzzle by writing Prolog code. This morning I tried a similar chess puzzle with ChatGPT. The task is to place a queen, king, rook, bishop, and knight on a 4 by 4 chessboard so no piece attacks another. Of course there’s not […] Writing Prolog with ChatGPT first appeared on John D. Cook.
- RSA munitions T-shirtJun 13, 2026John
Back when the US government classified strong encryption as “munitions,” RSA public key cryptography was illegal to export. In 1995, Adam Back protested this by creating a terse, obfuscated implementation of RSA in Perl code and used it as an email signature. The code was also printed on T-shirts. The shirt was classified as munitions […] RSA munitions T-shirt first appeared on John D. Cook.
- Solving a chess puzzle with Claude and PrologJun 11, 2026John
Prolog is the original logic programming language. The name comes from programming in logic. More specifically, the name comes from programmation en logique because the inventor of the language, Philippe Roussel, is French. Prolog has its advantages and disadvantages. One of the advantages is that the language represents logical problems directly. One of the disadvantages […] Solving a chess puzzl
- Formally proving a calculation with Claude and LeanJun 10, 2026John
I ran an experiment today to see whether Claude [1] could generate Lean code to prove a calculation at the bottom of this post, six lines of calculus. I started with this prompt This page contains a mathematical proof that a Fourier coefficient, a_n, is given in terms of a Bessel function. The LaTeX source […] Formally proving a calculation with Claude and Lean first appeared on John D. Cook.
- Pulling on a threadJun 10, 2026John
Often there’s a thread running through a sequence of my posts. Sometimes I make this explicit and sometimes I don’t. The latest thread started with this post commenting on a tweet that observed that exp(−x²) ≈ (1 + cos(sin(x) + x))/2. Some people said online that that the approximation is simply due to the first […] Pulling on a thread first appeared on John D. Cook.