MoreRSS

site iconJohn D. CookModify

I have decades of consulting experience helping companies solve complex problems involving applied math, statistics, and data privacy.
Please copy the RSS to your reader, or quickly subscribe to:

Inoreader Feedly Follow Feedbin Local Reader

Rss preview of Blog of John D. Cook

Las Vegas, Monte Carlo, and Integer Factorization

2026-11-26 21:14:07

Monte Carlo algorithms typically have a fixed runtime but a variable error rate.

Las Vegas algorithms have a variable runtime but a fixed (i.e. zero) error rate.

Stanisław Ulam came up with the idea of Monte Carlo methods in 1946 and Nicholas Metropolis coined the term “Monte Carlo” the next year.

László Babai coined the term “Las Vegas algorithm” in 1979 as a pun on Monte Carlo.

Las Vegas factoring algorithm in the news

There’s a new paper on GitHub titled Unconditional Integer Factorization in Time LN[1/3, O(1)]. It is a Las Vegas algorithm because it always [1] returns a correct factorization, though the time it takes to execute is random.

What is unconditional about the new algorithm? The analysis of the new algorithm does not depend on any unproven assumptions. Before there was a proof of the (Generalized) Riemann Hypothesis, many theorems were conditional because they assumed the GRH. The fastest integer factorization algorithms are not dependent on GRH but are dependent on other widely believed but unproven conjectures.

The notation LN[α, c], commonly used in computational number theory, stands for

exp(c (log N)α (log log N)1−α)

The fastest commonly used factorization method at this time is the GNFS (general number field sieve). Its runtime is

LN[1/3, (64/9)1/3 + o(1)] ≈ LN[1/3, 1.923]

This means that the c term is (64/9)1/3 = 1.923 plus a term that goes to zero as N increases.

For the new algorithm, the α term is the same as GNFS but the c term is something less than 105. This is a bound on the worst-case expected time. The runtime is not as good as GNFS but the runtime proof does not depend on any unproven assumptions. The best unconditional algorithm before this recent result was LN[1/2, 1].

 

[1] Las Vegas algorithms halt with probability 1. In practice they terminate, but strictly speaking they are partial functions, functions that give a correct result when they terminate.

The post Las Vegas, Monte Carlo, and Integer Factorization first appeared on John D. Cook.

Covering a body with eight smaller copies of itself

2026-11-25 22:51:58

It’s obvious that you could cover a cube with smaller cubes. You could, for example, take a cube with side 1 and cover it with cubes of side ½ centered on each corner.

It’s not as obvious how you would cover a ball with smaller balls, but you could cover the unit ball with balls of radius ½√3 centered at the points (±½, ±½, ±½).

Covering a sphere with eight smaller spheres

In fact, you could cover a ball with four smaller balls [1].

Now consider an arbitrary convex shape K in three dimensions with non-empty interior. Is it possible to cover K by copies of itself? Since K has non-empty interior, you could cover K by putting a smaller version of K around every point. And if K is compact, then this cover has a finite subcover. But there might be a lot of elements in this finite cover. What’s the minimum number possible in general? It takes eight cubes to cover a cube, so the minimum is at least 8. But could some odd shape take more?

Hadwiger’s covering conjecture says that K can be covered by eight copies of itself. That is, there exists a scaling constant 0 < λ < 1 and shift vectors vi such that

K \subseteq \bigcup_{i=1}^8 (\lambda K + v_i)

Dror Aiger, Sariel Har-Peled, and Goran Žužić posted a proof of Hadwiger’s conjecture on arXiv yesterday. The abstract to their paper says “The proof was discovered using an experimental harness on top of Gemini 4 Carbon and formally verified in Lean 4.”

I’ve heard good things about the Google’s new Carbon model. This is the first announcement of a major theorem proved with the assistance of a Google model that I’ve noticed.

Related posts

[1] Inscribe the vertices of regular tetrahedron on the unit sphere, then multiply the vectors representing the vertices by ⅓. Center spheres of radius ⅔√2 at each vertex.

The post Covering a body with eight smaller copies of itself first appeared on John D. Cook.

Polynomials and Planets

2026-11-25 21:44:21

A couple days ago I wrote about how the force of gravity varies over the surface of an oblate planet. Earth is slightly oblate, i.e., it has an equatorial bulge, and this oblateness has a significant effect on satellite orbits. More on that here.

The fictional planet Mesklin in Hal Clement’s novel Mission of Gravity is extremely oblate due to its rapid rotation, and apparent gravity varies by two orders of magnitude between the equator and the poles. As science fiction authors often do, Clement took some aspect of familiar experience and exaggerated it to make it easier to appreciate.

The gravitational potential of an oblate spheroid as a function of the polar angle θ is proportional to

1 − J2P2(cos θ)

where P2 is the second Legendre polynomial. There are more terms of the form

J2nP2n(cos θ)

but the most significant term is the one with coefficient J2, hence the J2 effect.

I learned about Legendre polynomials long before I learned about gravity calculations, and so my first reaction when seeing the result above would be that gravitational calculations are another example of places where Legendre polynomials pop up. While this is true, it’s historically backward. Legendre discovered the polynomials that now bear his name because they came up in his gravitational calculations.

It would be more historically informed to say that the polynomials falling out of Legendre’s exploration of gravity have found applications elsewhere, and often for the same reasons: because they fall out of calculations involving radial symmetry. That’s why they appear in E&M, acoustics, and quantum mechanics.

Legendre polynomials also appear in applications that have nothing to do with radial symmetry. For example, the most common form of Gaussian quadrature is based on Legendre polynomials. More on that here.

The post Polynomials and Planets first appeared on John D. Cook.

Taking a password joke seriously

2026-11-24 23:16:48

“I’m sorry but your password must contain 1 char each from: Arabic, Chinese, Thai, Korean, Klingon, Wingdings and an emoji”

This was a message from Finley Creative (@FinleyCreative) to Jeff Atwood (@codinghorror) on March 3, 2016. The original post seems to have gone away.

You could write a script to generate a password according to these rules. How secure would it be?

Multiplying the number of characters from each category gives

153 * 20992 * 57 * 11172 * 38 * 196 * 1409 = 21463556813227081728

possibilities. You could get different numbers depending on how you interpret each of the words in the rules. For example, the calculation above counts Arabic and Thai letters, but Klingon counts 26 letters, 10 digits and 3 punctuation marks.

Allowing the characters to appear in any order multiplies the number of possibilities by 7!  = 5040. This corresponds to 76.5 bits of entropy, about the same as 13 alphanumeric characters (upper and lower case).

You could generate a password as above, then using something like Base 58 encoding to turn into something you could type on a standard keyboard.

What if you wanted to use the seven Unicode characters as a password without converting them to ASCII characters first? This would be asking for trouble due to possible different encodings of the Unicode characters. Besides, sites that insist that your password contain a “symbol” can be quite restrictive in what symbols they allow.

The post Taking a password joke seriously first appeared on John D. Cook.

Memorable 12-digit primes

2026-11-24 22:13:51

There’s an old joke about having to enter a 12-digit prime number to continue using a program. I wrote about this years ago, on how to use Python to come up with a 12-digit prime. But suppose you do this often, and so you’d like memorize a 12-digit prime so you could enter it without having to run a Python script.

Here’s an easy one: 999999999989. The following code verifies that this number is prime.

>>> from sympy import isprime
>>> isprime(999999999989)
True

Major system encoding

Maybe that’s too easy, so you’d like to first find a 12-digit prime, then memorize it using the Major memory system.

>>> import random
>>> while True:
...     candidate = random.randint(10**11, 10**12 - 1)
...     if isprime(candidate):
...         print(candidate)
...         break
...
298412857819

To encode 298412857819, you might come up with “knob o’ fire, tin foil, cave tuba.” These things look ridiculous when written down, but they actually work, especially when you come up with them yourself: it’s hard to reuse someone else’s mnemonics.

Working backward

To come up with a mnemonic that looks reasonable in writing, you might approach the problem the other way around: generate memorable phrases until one happens to encode as a 12-digit prime. I asked Grok to do this, and it came up with “A young man sits near the lake” which decodes to 273201024157.

>>> isprime(273201024157)
True

I read a book on memory tricks one time, and the chapter on the Major system began by stating some ordinary sentence and the corresponding number, then asked which you’d rather memorize. This was highly misleading. The author came up with the mnemonic first then calculated the number.

Mnemonics in practice

In practice the number comes first: you construct a mnemonic for a number; you don’t start with a mnemonic and search for a number it fits. And you are far more likely to come up with nonsensical streams like “knob o’ fire, tin foil, cave tuba” than prose like “A young man sits near the lake.” The system works, with practice, but it doesn’t look like it would work when you write down the mnemonics. The fact that the series of words is nonsensical may help you form durable mental images.

If you try to remember “A young man sits near the lake” you have to remember a sequence of words, not a sequence of images. “A young man sits near the lake” and “A young man sitting near a lake” correspond to the same mental image, but they’re different sequences of words and decode to different numbers. A sequence of words might be easier to remember in the short term, but a sequence of vivid mental images sticks better over time.

To be fair, “knob o’ fire” is also fragile, since “o” could easily become “of”. But this goes back to what works in practice versus what looks like it would work in writing. I chose “knob o’ fire” because it looked better in writing than some other alternatives I came up with.

In practice people who use the Major system to remember words often use pegs, fixed encodings of sequences of digits, rather than improvising encodings. This eliminates ambiguities. For example, suppose one of your pegs is “rover” for 484 and you imagine a Mars rover. Then when recalling a number, there’s no ambiguity whether “Mars rover” should decode to 340 (for Mars) or 484 (for rover), assuming you have a different peg for 340, such as Morse code.

The post Memorable 12-digit primes first appeared on John D. Cook.

Finite Projective Spaces

2026-11-24 07:49:05

Just as there are finite projective planes, there are also finite projective spaces of higher dimension.

The axioms of a projective space are

  1. Any two distinct points lie on exactly one line.
  2. If A, B, C, and D are distinct points and the lines AB and CD meet, then the lines AC and BD also meet.
  3. Every line contains at least three points.
  4. There are at least two lines.

The second axiom is subtly different from its counterpart for projective planes. It allows for skew lines but not parallel lines. There’s no explicit concept of dimension in these axioms, but dimension can be well-defined by induction.

What I find most interesting about finite projective spaces is that they are in some sense simpler than projective planes. Usually higher dimensions allow for more complicated behavior, but at least as far as classification goes, higher dimensional spaces are simpler.

Finite projective planes are not determined by the number of points they contain. As mentioned in this post, there are four different projective planes with 10 points. It is unknown how many different projective planes there are with 17 points; there are at least 22. But for dimension d ≥ 3, there is at most one projective space with a specified number of points.

Given a prime power q, there is a unique field F with q elements, and one can construct a projective space of dimension d over F analogously to how one constructs a real projective space of dimension d: Take the non-zero vectors in Fd + 1 and mod out by non-zero scalar multiples. And up to isomorphism this is the only way to construct a finite projective space if d ≥ 3. In technical terms, finite projective planes can be non-Desarguesian but higher-dimensionsal projective spaces cannot.

Related posts

The post Finite Projective Spaces first appeared on John D. Cook.