TITLE: Statistics of Extended GCD
QUESTION [13 upvotes]: Consider a coprime pair of integers $a, b.$ As we all know ("Bezout's theorem") there is a pair of integers $c, d$ such that $ac + bd=1.$ Consider the smallest (in the sense of Euclidean norm) such pair $c_0, d_0$, and consider the ratio $\frac{\|(c_0, d_0)\|}{\|(a, b)\|}.$ The question is: what is the statistics of this ratio as $(a, b)$ ranges over all visible pairs in, for example, the square $1\leq a \leq N, 1 \leq b \leq N?$
Experiment shows the following amazing histogram:
EDIT by popular demand: the histogram is for an experiment for $N=1000.$ The $x$ axis is the ratio, the $y$ axis is the number of points in the bin. The total number of points is $1000000/\zeta(2),$ so there are $100$ bins each with around $6000$ points.
But no immediate proof leaps to mind.

REPLY [3 votes]: Here is an attempt to give a somewhat finer grained view of the distribution. The set of ratios $\sqrt{\frac{s^2+t^2}{a^2+b^2}} \subset(0,\frac{1}{2})$ are essentially  the values in the first half of the Farey sequence $\lbrace \frac{p}{q} | \gcd(p,q)=1,\ 2p \le q<N\  \rbrace$. This has already been pointed out but I'll give a simple (if less nuanced) justification. Then I'll mention how that sequence is and is not smoothly distributed.
Instead of looking at all the relatively prime pairs $(a,b)$ with $1 \le a,b\le N$ I'll just consider those with $a<b$ since order is irrelevant for the question asked and $(a,b)=(1,1)$ is an extreme outlier. There are non-negative integers $s,t$ with $|as-bt|=1$ and just one such pair with $\sqrt{\frac{s^2+t^2}{a^2+b^2}}<\frac{1}{2}$. This ratio turns out to be very close to $\frac{t}{s}$. Then $(0,0),(t,s),(a,b)$ and $(t+a,s+b)$ are corners of a long thin parallelogram with area 1 and (thus) no integer points on its boundary or interior. Because the sides are very nearly parallel, the ratio $\sqrt{\frac{s^2+t^2}{a^2+b^2}}$ of their lengths is quite close to $\frac{t}{a}$ and even closer to $\frac{s}{b}$ (in fact they are convergents to the continued fraction for that irrational number). So that set of ratios is quite close to the lower half of the set of fractions 

LATER 
For fixed $b$ the discrepency between $\sqrt{\frac{s^2+t^2}{a^2+b^2}}$ and $\frac{s}{b}$ is almost exactly $\frac{1}{b(2b^2+1)}$ for $\frac{1}{b}$ and increases to $\frac{2}{b(4b-1)}$ for $\frac{b-1}{b}$  

Let $\mathcal{H}_N=\lbrace \frac {p}{q} |\frac{p}{q}\le \frac{1}{2} ,\gcd(p,q)=1,q \le N \rbrace$ The letter $\mathcal{H}$ is because this is half a Farey sequence. It is known that $P(N)=|\mathcal{H}_N|=\frac{3N^2}{2\pi^2}+O(N\log N)$. How evenly spaced are these? There are  $P \approxeq \frac{0.15}{N^2}$ points in an interval of width $1/2$ so perfectly even spacing would put the kth point at $\frac{k}{2P}\approx\frac{3.3k}{N^2}$. However a fraction $\frac{p}{q}$ with $q$ small will be about $\frac{1}{qN}$ from the next nearest points. Hence  the largest point other than $\frac{1}{2}$ is $\frac{1}{2}-\frac{1}{N}$ (replace N by N-1 in the even case) and the smallest point is $\frac{1}{N}$ which seems far from $\frac{3.3}{N^2}$  These empty zones force other points closer together, the first few points are only separated by about $\frac{1}{N^2}$. I can't resist an attempt to put in a picture of Ford Circles. A disk of radius $\frac{1}{q^2}$ is centered at $(\frac{p}{q},\frac{1}{q^2}).$ Disks are either disjoint or tangent. One can see the enforced distance around fractions with small denominators. On the other hand, each disk is put into the largest gap present (albeit not exactly at the center). This is a subtle topic. I'll just mention that a conjecture about the distance (in the $\ell_1$ or $\ell_2$ norm) between the sorted vector of Farey fractions and the evenly spaced vector $[0,1/2P,1/4P,\cdots$ is equivalent to the Riemann Hypothesis.
alt text http://www.freeimagehosting.net/uploads/2e24bdc608.png
With the appropriate bin size and placement things might come out fairly even. The chart by the OP uses 100 bins for roughly 608,382 points. As I said, the results should be essentially the same as for $\mathcal{H}_N$. The very first bin is smashed against the y axis but it is below average by 213 and the next two bins are over by about 148 and 30 respectively. It is easier to see that the bin containing $\frac{1}{3}$ ($ 0.330<1/3<0.335$) is deficient from the average by about 95 points (by my calculations) the bin before it is about average but the one after is up by about 68 points. The last bin is under by 33 and the one before it over by 24. My other answer discussed an example made with rounding rather than truncation and a number of bins ($2520=8 \cdot 9 \cdot 5 \cdot 7$) that put simple fractions in the center of a bin. This allowed more choppy behavior.