# Probabilistic (randomized) algorithms before "modern" computer science appeared

Edit: I choice the answer with highest score by December 06, 2012.

This is a soft question.

The concept of (deterministic) algorithms dates back to BC. What about the probabilistic algorithms?

In this wiki entry, Rabin's algorithm for the closest pair problem in computational geometry was given as the first randomized algorithm (year???). Lipton introduced Rabin's algorithm as the start of the modern era of random algorithms here, but not as the first one. I also know many algorithms for probabilistic finite automata (a very simple computational model) discovered during 1960s.

Do you know any probabilistic/randomized algorithms (or method) even before 1960s?

or

Which finding can be seen as the first probabilistic/randomized algorithm?

• The age-old idea of tasting a spoonful of boiling soup to check if it tastes right is essentially random sampling, a probabilistic algorithm with provable guarantees. Sep 11, 2012 at 20:18
• Rabin's algorithm was published in 1976, long after "modern" computer science was well-established. Sep 11, 2012 at 21:53
• Could you perhaps clarify if there are any criteria which you would like to impose on "algorithms", in order to clarify whether you think e.g. that natural phenomena which predate humanity by billions of years represent "algorithms", as suggested by some of the responses below? Sep 13, 2012 at 16:05
• @NieldeBeaudrap: What in my mind was some mathematically well-defined algorithms. (But, personally, I like arnab's answer very much :)) Sep 15, 2012 at 15:13

This is discussed a bit in my paper with H. C. Williams, "Factoring Integers before Computers"

In a 1917 paper, H. C. Pocklington discussed an algorithm for finding sqrt(a), modulo p, which depended on choosing elements at random to get a nonresidue of a certain form. In it, he said, "We have to do this [find the nonresidue] by trial, using the Law of Quadratic Reciprocity, which is a defect in the method. But as for each value of u half the values of t are suitable, there should be no difficulty in finding one."

So this is one of the first explicit mentions of a randomized algorithm.

• This is a really nice reference. Has Pocklington's Algorithm since been derandomized? Tangentially, I love your work - both in and out of CS - in particular your algorithm for Bachet's conjecture (the paper was hard to find a copy of though!) but also your civil liberties work. Have you watched Errol Morris's "Mr. Death?" Sep 12, 2012 at 17:02
• interesting. it's reminiscent of randomized primality testing Sep 13, 2012 at 15:43
• And a Las Vegas algorithm too! Nice reference. Sep 13, 2012 at 15:43
• Very nice reference. Sep 14, 2012 at 13:53
• speaking of factoring before computers, does anyone know what Lehmer knew about the pocklington algorithm, or any other randomized algorithms, or whether Lehmer actually ever implemented it on his sieve factoring computer? the two apparently have some connection with the Pocklington-Lehmer primality test acc to wikipedia
– vzn
Sep 20, 2012 at 18:07

Buffons needle algorithm for estimating $\pi$, basically a Monte Carlo method, dates to publication in 1777. note that Monte Carlo methods date to the 1940s with the US "Manhattan" atom bomb project & were coinvented by Ulam, Von Neumann, and Metropolis.

• Actually this is related to a question that I asked. Nobody knows exactly who devised the algorithm that many people take to be Buffon's needle nowadays. Sep 11, 2012 at 21:33
• stated more exactly— there is a clearcut Buffon needle algorithm which involves dropping needles on stripes, and an apparently much different "random point vs circle" algorithm as you mention in that question which some people seem to incorrectly attribute to Buffon, with different, more modern, but uncertain origins.
– vzn
Sep 15, 2012 at 16:28

The Metropolis–Hastings algorithm was published in 1953 and dates back earlier to the Manhattan project, long before Rabin. Like many of the early randomized methods given in other answers, it is a Monte Carlo algorithm.

Is it possible that the claim on the Wikipedia page is a garbled form of the claim that Rabin's was the first Las Vegas algorithm?

In my opinion, natural evolution is a good and rather old probabilistic algorithm :-)

• +1 although the description of the process as probabilistic us much more recent. ;-) Sep 12, 2012 at 14:41
• "Algorithm" suggests that there is a problem it is trying to solve; but it isn't. It isn't even "trying" to make animals which are better at surviving; creating animals which are adapted to its environment is just a byproduct (one which is not always achieved, as extinction and mass-extinction events make evident). In this respect, evolution is no more an algorithm than gravity is; it's just this thing which sort of happens. Sep 13, 2012 at 15:33
• MDB is dead on! evolution is a genetic algorithm that selects for evolutionary fitness and science is still catching up with all the implications of this.... ie its an active area of research. it hasnt been pointed out much or widely appreciated, but the phenomenal success of GAs in CS is actually strong mathematical/scientific evidence of the reality of biological evolution theory. however, concede it is definitely different than other "algorithms" in some key ways.
– vzn
Sep 13, 2012 at 15:44
• @vzn: a "genetic algorithm", first of all, selects for a fitness function which we impose for a specific purpose. We use evolution as a tool to do something in that case. But that doesn't mean that biological evolution is an algorithm to do anything. Using the gravity analogy again, is there a meaningful sense in which all waterfalls are algorithms, just because we sometimes use waterfalls to generate electricity? Sep 13, 2012 at 15:56
• @vzn: I merely assert that "an algorithm" should entail well-defined parameters of probability of success, not to mention that there should be an agent which carries it out. The only 'agent' which could be said to carry out "evolution" would be an entire ecosystem. What should we say that the ecosystem is "trying" to achieve? I would as readily say that you are anthropomorphising nature. I only demand that "applying an algorithm" entail some amount of goal-oriented intentionality, applied by humans or no. In what sense can a process without a goal represent an "algorithm"? Sep 15, 2012 at 18:08

The Gaussian normal curve/distribution of statistics can be "computed" by many very simple physical processes. One of the simplest is a board with a pin array in a triangular grid (also known as a "Galton box" dating to the 1800s) where pins are offset 1/2 square distance on alternating rows. Dropping balls repeatedly from the same position, the balls randomly displace left or right with probability 0.5. The cumulative distribution recorded at bottom positions yields the Gaussian curve/normal.

• +1 just because I’m currently designing a logo for our statistics research group and the Galton Box was our first idea (but turns out to be too complex for a logo). Sep 12, 2012 at 14:40

There is a paper about randomized algorithms in 'primitive' cultures.

Using oracles (e.g. chicken bones, stones) to decide on where to hunt can be seen as a randomized algorithm. One can argue that randomizing the hunting grounds prevents game adaption and overhunting.

one of Einsteins 1905 "miracle" papers was on brownian motion, a classic physical example of a random walk and yields a formula (ie, basically an algorithm, if the physical process is the "computer") for estimating/calculating particle (molecule) diameter given other known physical constants and the observation/measurement of the (random) particle displacement over time. this paper also served as early theoretical/experimental/foundational evidence for the atomic theory of matter.

• Again as with evolution: though the motion may be random, and may be modelled by a random walk, what algorithm does this represent? While some algorithms use random walks, this does not mean that all random walks represent algorithms (any more than any string of words in English represents prose just because all English prose consists of words in English). Sep 13, 2012 at 15:53

another answer in the vein of JS's number theory direction. one of the earliest analog-digital computers constructed is the Lehmer sieve dating to ~1932, predating electronic computers by about a decade. it basically computes remainder of division mod $n_i$ for a finite number of $n_i$ and applies the chinese remainder thm. for larger numbers it computes probabilistic answers to number theory questions including factoring. although the terminology at the time may not have referred to "probabilistic algorithms" it was possibly used in this way in some cases. (in this way it also has some similarity to the Fermat probabilistic prime test.)

the machine also bears some similarity to the Babbage differential engine (~1830s). its not entirely inconceivable that Babbage or Lovelace may have envisioned something similar to probabilistic algorithms. the machine(s) can certainly be used to implement probabilistic algorithms, borrowing modern theory and superimposing it on the past.

Lehmer mod n & factoring machine

• Can you describe the sense in which it computed probabilistic answers for large numbers? A quick search doesn't I can't seem to find any references to that online. Sep 15, 2012 at 17:23
• my understanding, it was used [among other purposes] to find smaller factors of large test numbers similar to sieve of eratosthenes. if the large number passed, it is "probably not composite" or "possibly prime" or a "prime candidate". unfortunately the internet is not very good with historical references & origins [even wikipedia], books are better. more details at bottom of this page, "types of problems Lehmer was attempting to solve" by Dr mike williams, head curator of the computer history museum of CA
– vzn
Sep 15, 2012 at 17:41
• the machine(s) can certainly be used to implement probabilistic algorithms — So? As opposed to other machines that can't? Sep 15, 2012 at 18:45
• although the terminology at the time may not have referred to "probabilistic algorithms" it was possibly used in this way in some cases — [citation needed] If you have evidence that "possibly prime" is a formal statement about probability, and not simply a heuristic description, please cite it. Otherwise, please stop speculating. Sep 15, 2012 at 18:48
• dont have the full contents of Lehmers papers available (not even sure what all he published), but the pocklington randomized ref is supported by a single line of one of his papers. what is the criteria? it seems all that is required that Lehmer run the machine on some number greater than $n_1 * n_2 * n_3 * n_x$ for the largest $x$ on the machine, and make some kind of reasonable observation about the result, not necessarily written down.... seems plausible to me....
– vzn
Sep 16, 2012 at 2:43

here are some cases of the early and even ancient/prehistory beginnings of concepts related to randomized algorithms.

• consider the Sieve of Eratosthenes, approx 2 millenia old. somewhat implicit in the algorithm would be the idea of "stopping early" in marking off the prime intervals, before all intervals up to $n/2$ have been marked off. it is clear that the "later" longer intervals are less likely to mark off a given number under consideration. in other words, its a rough visualization of the basic number theory fact that "most composite numbers have small factors" and that testing a bunch of small factors is enough to rule out many composite numbers. this concept would probably be understood by the Greeks.

• games of chance and gambling are very ancient. from modern theory, games have strong similarities if not direct connections to algorithms. gambling/gaming dice are known to be at least five millenia old.

• the Greeks & Romans also had the concept of drawing straws where the person drawing the shortest straw lost. similar to dice, its in a sense the simplest possible algorithm to make a single random choice.

• full disclosure, there is a tinge of bloody history and connection. in other answer MDB mentions evolution. part of evolution is natural selection which also has parallels to human warfare — apparently an intrinsic part of the evolution of human cities/societies. in a sense a war is a crude semirandom algorithm for "something" which sociologists & historians still argue over exact causes. theft/looting? allocating resources? territory? political power? slaves? (etc.) the Romans also had a grisly practice called decimation (the modern word actually derives in etymology from the ancient one!) in which, as punishment for mutiny or cowardice, every 10th soldier selected at random was executed by remaining soldiers. it might seem a forgotten and atavistic practice, but it seems to have some parallel to modern russian roulette, a "modern" randomized quasi-game for suicide.

• That's not what I'm asking about; I'm asking about whether they reasoned about the relative frequency of composite numbers in the way that you describe. Sep 13, 2012 at 16:03
• I'm afraid I'm not interested in vague generalities, and it seems quite obvious that we disagree fundamentally in what an "algorithm" is. I'm interested in more than just "phenomena". Otherwise, we may as well cite all quantum mechanical events after the Big Bang as examples of "randomized algorithms", which makes the whole subject trivial. Sep 13, 2012 at 16:17
• "soft question" doesn't mean a question with infinitely flexible boundaries; "historical overview" is not the same as historical revisionism. Sep 13, 2012 at 16:25
• Your 'hint' to me about evolution, nor your casting me as wasting time on a question I don't like, nor your evasion of my earlier question, were respectful. And in fact, your speculating that the Greeks probably knew about what you're talking about but didn't bother to write about it is exactly one of the things which "historical revisionism" can refer to. (Maybe Archimedes invented decimal notation, but didn't bother to make any record; after all, the Sand Reckoner is quite close to place notation, and the Greeks did use a base-10-like system. But should we take the idea seriously? No.) Sep 13, 2012 at 16:36
• I agree that it's concievable, and that it isn't even very far-fetched -- aside, of course, from the fact that we don't seem to have any record of the Greeks talking about probability per se. But if there's an actual record of it, you should be able to actually point it out. Otherwise, it's speculation, not history. Sep 13, 2012 at 16:48

JS mentions number theory. Fermat is credited with the Fermat primality test, a probabilistic algorithm which dates to the 1600s and serves as a precursor to more modern primality tests such as Solovay-Strassen and Miller-Rabin. [it would take a historian specializing in math & number theory to try to pinpoint exactly what Fermat knew about it versus modern knowledge which is much more complete about the structure of its pseudoprimes (false positives) etc.]

• Can you cite Fermat as having used his test as a way of filtering out randomly selected integers as non-primes (as opposed to just an interesting property that primes have)? Or perhaps cite an early author who suggests doing so? Sep 13, 2012 at 15:35
• as stated the exact details are better left to a professional historian. however note [addendum; should have mentioned this] the simple historical fact that fermat is credited as the founding coinventor of probability theory along with pascal, laying the groundwork in a series of letters in the mid 1600s.
– vzn
Sep 15, 2012 at 5:12
• it's not really appropriate to propose answers based on what you believe someone else might be able to show. Again, that is speculation. Sep 15, 2012 at 11:13
• @vzn: If Fermat had realized that Fermat's Little Theorem was a good primality test, he would have calculated that the 5th Fermat number was not prime. This was not done until Euler factored it more than 60 years after Fermat's death. Sep 15, 2012 at 15:43
• @vzn: [citation needed] Sep 15, 2012 at 18:43