The Dirichilet’s approximation Theorem is about using rational numbers to approximate any numbers. To state it formally:
If , then there exist integer and with such that .
I managed to write up a simple Mathematica code (when I say simple, it still took me about 1 hr to write up and satisfy with, I suck at programming)
Declaring all the necessary variables first.
\[Alpha] = E;
n = 1000;
seq = (Range[n + 1] - 1)*\[Alpha];
fracseq = FractionalPart[seq];
intervals = Partition[(Range[n + 1] - 1)/n, 2, 1];
found = 0;
k = 1;
Just like in the proof of the Dirichlet Therorem, we created a sequence, which are the fractional part of first n integer multiples of alpha. The intervals are created in a similar way.
A loop to find the very first instance that we have “two piegeons in the same piegeonhole”.
While[k < Length[intervals] && found == 0, If[ Total[Boole[IntervalMemberQ[Interval[intervals[[k]]], fracseq]]] > 1,
found = 1, found = 0
This is just checking that we have the piegeons in the right place.
k - 1
Total[Boole[IntervalMemberQ[Interval[intervals[[k - 1]]], fracseq]]]
intervals[[k - 1]]
We have a selection criterion here, to select the first two piegeons in the hole.
Boole[IntervalMemberQ[Interval[intervals[[k - 1]]], fracseq]];
Pick[seq, selectseqcriterion, 1];
i = Pick[Range[n + 1] – 1, selectseqcriterion, 1][];
j = Pick[Range[n + 1] – 1, selectseqcriterion, 1][];
‘a’ and ‘b’ are the denominator and numerator of the rational approximation to the real number alpha.
a = j - i
b = Floor[j*\[Alpha]] - Floor[i*\[Alpha]]
This is just a check that the function works.
Abs[a*\[Alpha] - b] < 1/n
Abs[\[Alpha] - b/a] <= 1/(a^2)
N[Abs[\[Alpha] - b/a]]
So this simple program works. The exercise and theorem came from Kenneth Rosen’s “Elementary Number Theory”, and it certainly a good exercise to do.