ln n!

23/02/2016

In the course of analyzing an algorithm, I used the simplifying hypothesis that the cost function is

\displaystyle c(n)\approx\sum_{i_1}^n \lg i=\lg n!.

That expression is cumbersome but we can get a really good simplified function to use as a proxy. Let’s see how.

Read the rest of this entry »


OB Sqrt

22/12/2015

I have discussed the problem of efficient square root calculation quite a few times. And yet, while reading Rudman’s The Babylonian Theorem, I found yet another square root algorithm. The Old Babylonian square root algorithm. Let’s have a look on how it works.

wood

Read the rest of this entry »


Eratosuite

15/12/2015

The other day in class, we were looking at recurrence relations and how to solve them with the characteristic equation. Among the examples I gave was a recurrence that seemed to give a good number of primes numbers. Are there many of those? How do we find them?

Eratosthene.01

Well, we need two things: a method of testing if a given number is prime, and a method of generating recurrences—parameters and initial conditions. Well, make that three: we also need to generate the suite generated by the recurrence relation. Let’s go!

Read the rest of this entry »


Pythagorean Primes

01/12/2015

Last Week, we had a look at Pythagorean triples. Remember: a Pythagorean triple is three natural numbers (positive integers) such that a^2+b^2=c^2. Most of the times, even with a and b natural numbers, c is irrational. Sometimes c is prime; sometimes c^2 is. Is either frequent?

Read the rest of this entry »


Pythagorean Triples

24/11/2015

The Pythagorean theorem, linking the sides of a right triangle, is one of the most useful basic mathematical identities. It is also one of the more entertaining. Loomis, in his book The Pythagorean Proposition (1968), gives 370 different proofs of the theorem. However, we’ll more often interested in computing the length of the hypotenuse, or finding triples—three natural numbers that makes the theorem hold—than finding a new proof for it.

There is, of course, the smallest possible triple (defined as involving the smallest possible numbers) 3, 4, 5. But there are infinitely more triples. Let’s see how we can generate them.

Read the rest of this entry »


Rational approximations of π (Divertimento)

10/11/2015

While reading on the rather precise approximation 355/113 for π, I’ve wondered how many useful approximation we could find.

pi-pie

Read the rest of this entry »


π like an Egyptian

15/09/2015

In the Rhind Mathematical Papyrus (RMP) we find that the Egyptians used the approximation

\displaystyle 4\times\left(\frac{8}{9}\right)^2 =4\times\frac{64}{81} =\frac{256}{81} \approx{3.16}

For \pi. The RMP shows how to arrive at this result: you construct a 9\times{9} grid and draw an octagon on it that approximates the circle. Turns out this irregular octagon as \frac{7}{9} of the area of the bounding square. But the ancient Egyptians rounded that value, for reasons unknown, from 63 to 64 (I have a theory on why; but that may be a later post). This gives the above approximation.

egyptian-pie-crop-small

Read the rest of this entry »


King Solomon’s Bath

08/09/2015

In 1 Kings 7 (King James version), we read the description of Solomon’s molten sea:

And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about.

bath

…which I take is some kind of bath. Superficially, it seems to state that \pi=3, since the circumference of a circle of diameter d given by \pi d=2\pi r. But what if “round about” doesn’t strictly means “perfect circle”?.

Read the rest of this entry »


Comparing GPSes (yet more GPS data)

03/02/2015

In a few other entries, I’ve toyed with GPS, either getting or parsing the data with Bash, assessing or using the GPS data. However, when we use GPS, we suppose that the precision varies by brand and model&mdashsome will have greater precision—but our intuition tells us that two GPS devices of the same brand and model should perform identically. That’s what we’re used to with, or at least expect from, computers. But what about USB GPS devices?

162px-Gray_compass_rose.svg

So I got two instances of the same model+brand GPS. Let them call them GPS-1 and GPS-2. Do they perform similarly?

Read the rest of this entry »


Unfair Coin Tossing

27/01/2015

Suppose you want a fair coin, one that yields heads and tails with equal probability, but only have a bizarre coin that yields a side more often than the other. Can we remove the bias?

coin-obverse-small

John von Neumann gave us a surprisingly simple procedure to remove bias from a coin and yield a fair toss.

Read the rest of this entry »