How do I count thee? Let me count the ways?

Does every finite string of numbers appear within π ?

      In honor of Pi Day (March 14), I offer the following: Does every finite string of numbers like your social security number event...

Friday, March 13, 2026

Does every finite string of numbers appear within π ?

      In honor of Pi Day (March 14), I offer the following: Does every finite string of numbers like your social security number eventually appear somewhere within the decimal expansion of π ?

      So said Harold Finch, the computer genius on TV show "Person of Interest" ("You are being watched ... ") in a 2013 episode where he poses as a substitute high school math teacher.



      "Pi... keeps on going, forever, without ever repeating. Which means that contained within this string of decimals, is every single other number. Your birthdate, combination to your locker, your social security number, it's all in there, somewhere. And if you convert these decimals into letters, you would have every word that ever existed... all of the world's infinite possibilities rest within this one simple circle."

      We know π is irrational; it cannot be expressed as the quotient of two integers.   Video

      An irrational number has an infinite, non-repeating decimal expansion.

      A number is defined as normal if any finite string of numbers like your social security number will eventually appear somewhere in its decimal expansion. (The is a simpler version of a more complicated mathematical definition , but it is sufficient for this discussion.) Mr. Finch is claiming π is a normal number. However, mathematicians have not yet proved this. (I once attempted to add this last statement and the fact that Finch was wrong, to Wikipedia's Person of Interest page, but the Wikipedia editors declined it.)

      Although π is defined geometrically as the ratio of a circle's circumference to its diameter, mathematicians calculate long sequences of π using infinite series, rather than physical measurements. Various websites such as angio provide files containing up to 1 million digits of π.

      I wrote some R code that would take a number (or a word, converted to a number) and search for where that number could be found within π. I decided the first 100,000 digits of π were enough for me. Of course, the fact that a number can not be found within the first 100,000 digits, does not preclude that it can be found in the next 100,000 digits, or the next 1 million digits. And so on. Infinitely many digits goes on for a long time.

      I tested these examples:

  • "Eggs". e = 5, g = 7, g = 7, s = 19.   57719 appears starting at the 6026 th digit of π.
  • "0123" appears starting at the 27846 th digit of π.
  • "01234567" was not found in the first 100k digits. But according to The Pi Search Page it can be found starting at the 112,099,767 digit.
I did not try "0123456789", but another source says it was not found in the first 2 billion digits.

      Here is my R code. Happy Pi Day!


# Symbol for pi is \u03c0
library(stringr)
library(readr)

find_in_pi <- function(input_value) {
  # 1. Load the Pi data
  data.raw <- readr::read_file("https://assets.angio.net/100000.txt")
  data.vec <- unlist(str_split(data.raw, pattern = ""))
  data.vec <- data.vec[-c(1, 2)] # remove '3.'
  pi_string <- paste(as.character(data.vec), collapse = "")
  
  # 2. Process Input: Determine if it's a word or a numeric string
  # Convert to character and lowercase for uniformity
  clean_input <- tolower(as.character(input_value))
  
  if (grepl("[a-z]", clean_input)) {
    # It's a word: Convert letters to numbers (1-26)
    word_only <- gsub("[^a-z]", "", clean_input)
    z <- unlist(str_split(word_only, ""))
    q <- match(z, letters)
    search_target <- paste(q, collapse = "")
  } else {
    # It's already a number: Just strip non-digits (like decimals or spaces)
    search_target <- gsub("[^0-9]", "", clean_input)
  }
  
  # 3. Search Pi
  pos <- regexpr(search_target, pi_string)
  
  # 4. Handle Results
  if (pos[1] == -1) {
    return(paste0("The sequence '", search_target, "' was not found in the first 100k digits."))
  } else {
    start <- pos[1]
    end <- start + nchar(search_target) - 1
    return(list(
      found = search_target,
      start_index = start,
      end_index = end,
      index_sequence = seq(from = start, to = end)
    ))
  }
}

# Search for a word
find_in_pi("Eggs")

# Search for a number;  enclose in quotes if a leading zero
find_in_pi("01234")
find_in_pi("01234567")

End

No comments:

Post a Comment