# Does these arithmetic means of Pythagorean triangles converge?

Primitive Pythagorean triplets $$a^2 = b^2 + c^2, \gcd(b,c) = 1$$ are given by $$a = r^2 + s^2$$, $$b = r^2 - s^2$$ and $$c = 2rs$$ where $$r > s$$ are natural numbers. Let the $$n$$-th primitive triplet be the one formed by the $$n$$-th smallest pair in increasing order of $$(r,s)$$.

Claim 1: Let $$\mu_n$$ be the arithmetic mean of the ratio of the perimeter to the hypotenuse of first $$n$$ primitive Pythagorean triplets; then,

$$\lim_{n \to \infty}\mu_n = \frac{\pi}{2} + \log 2$$

Claim 2: Let $$\mu_x$$ be the arithmetic mean of the ratio of the perimeter to the hypotenuse of all primitive Pythagorean triplets in which no side exceeds $$x$$; then,

$$\lim_{x \to \infty}\mu_x = 1 + \frac{4}{\pi}$$

Update 8-Oct-2019: Claim 2 has been proved in Mathoverflow.

Data for claim 1: From the plot of $$\mu_n$$ vs. $$n$$ for $$n \le 5 \times 10^8$$ we observe that $$\mu_n$$ is approaching a limiting value which is somwhere between $$2.263942$$ and $$2.263944$$. The midpoint of the distribution of $$\mu_n$$ agrees with the above closed form to $$6$$ decimal places. Claim 2 has similar data.

Question: Are these limits known if not, can it be proved or disproved?

Sage code for claim 1

r   = 2
s   = 1
n   = sum = 0
max = 10^20
while(r <= max):
s = 1
while(s < r):
a = r^2 + s^2
b = r^2 - s^2
if(gcd(a,b) == 1):
c = 2*r*s
if(gcd(b,c) == 1):
n = n + 1
sum = sum + ((a+b+c)/a).n()
if(n%10^5 == 0):
print(n,sum/n)
s = s + 1
r = r + 1
• You could use the explicit forms for Pythagorean triples. I'm not sure if it will give you the answer but that's where I would start. Oct 3, 2019 at 11:06
• How did you obtain the experimental data? A naive implementation (asking my computer to find all primitive pythagorean triples satisfying the conditions, then computing the value of $\mu_n$) seems to take forever on my machine even for modest values of $n\approx 10^4$. Is there a smart way? Oct 3, 2019 at 11:21
• Oct 3, 2019 at 11:27
• Thanks! I doubt I'll be able to get anywhere, but I'll be thinking about this nice problem :) Oct 3, 2019 at 11:30
• I'm sure you've looked at this, but it's interesting to me to put this into trigonometric form. If one of the angles of the triangle is $\theta$, the ratio of the perimeter to the hypotenuse is $\frac{x+y+h}{h}=1+\frac{x}{h}+\frac{y}{h}=1+\sin{\theta}+\cos{\theta}$.
– Paul
Oct 3, 2019 at 12:07


Disclaimer: this answer has been edited to account for changes in the question and remove false claims.

For the first claim: parametrize Pythaogrean triples with the usual stereographic projection $$(a,b,c)=(q^2-p^2,2pq,q^2+p^2)$$ where $$0 and $$p,q$$ are coprime.

Then we seek the aymptotic behavior as $$r\to\infty$$ of the mean value of $$f(t)\deq \frac{2(t+1)}{t^2+1}$$

over all rational numbers $$0 such that

$$\h(t)

where for a rational number of the form $$p/q$$, $$p,q$$ coprime

$$\h(p/q)\deq \abs{p}\vee\abs{q}\text{.}$$

Write $$\mu_{\h,r}$$ for the probability measure associated over taking the mean over rationals $$0 such that $$\h(t).

Now, $$\mu_{\h,r}$$ represents a mean with respect to rationals $$t$$ such that $$\h(t). But since $$0, this is really a mean with respect to rationals such that the denominator $$q$$ is less than $$r$$. The sequences of such rationals are known as Farey sequences, and it is known that these are asymptotically equidistributed, so that the limiting measure is Lebesgue measure:

$$\lim_{h\to\infty}\mu_{\h,r}=\lambda\text{.}$$

Therefore the desired limiting mean value is

$$\int_0^1\frac{2(t+1)\mathrm{d}t}{t^2+1}=\frac{\pi}{2}+\log 2\text{.}$$

Edit: as @Blue pointed out in the comments, we must take into account excluding fractions for which both the numerator and denominator are odd. It is likely that these can also be shown to be equidistributed by Weyl's Criterion.

• For primitive Pythagorean triples, you also need the condition that $p$ and $q$ are not both odd. (For instance, $p=3$ and $q=5$ gives the non-primitive triple $(16, 30, 34)$.)
– Blue
Oct 3, 2019 at 13:18
• @Blue addressed issue Oct 3, 2019 at 14:13
• @KBDave This argument can be extended to show that the limit for the non-primitive case should also be $\pi/2 + \log 2$ since in this case we have the sequence $p/q$ where $\gcd(p,q) \ge 1$ and we can show that sequence of numbers $1/p,2/p,3/p,\ldots,(p-1)/p$ approach uniform distribution in $(0,1)$ as $p \to \infty$. Oct 4, 2019 at 0:54

I think the limit of the average perimeter/hypotenuse values depends on the order in which the Pythagorean triples are generated.

The program in the OP generates the triples $$(r^2+s^2, 2rs, r^2-s^2)$$ in order of increasing $$r$$. The description however was (before the edit) about taking the average over those triangles with the hypotenuse below some bound $$n$$ (and then letting $$n$$ go to infinity).

This bound changes the result because if $$r^2$$ is close to $$n$$, then $$s$$ cannot take values almost as high as $$r$$ because it is bounded by $$\sqrt{n−r^2}$$. This leaves out some more acute triangles (with $$s$$ near $$r$$) that have a low ratio, and so increases the value of the average. If you generate the triples in order of increasing $$r$$, those acute triangles are structurally shifted earlier in the sequence compared to if you generated them in order of increasing hypotenuse, therefore making all the partial averages smaller.

I get a limit of about $$2.2732$$ instead.

Here is the straighforward C# code I used. max is the (strict) upper bound on the hypotenuse length.

using System;

namespace test
{
/* max     average
* 10^7    2.2734207124719
* 10^8    2.27329667075612
* 10^9    2.27325757481033
* 10^10   2.27324525141887
* 10^11   2.27324135532923
*/
class Msepythlimit
{
static void Main()
{
long n = 0;
double sum = 0;
double max = 10000000;
for (long r = 2; r*r <= max; r++)
{
for (long s = 1 + r % 2; s < r && s * s + r * r < max; s++)
{
if (Gcd(r, s) == 1)
{
long a = r * r + s * s;
long b = r * r - s * s;
long c = 2 * r * s;
n++;
sum += (double)(a + b + c) / a;
if (n % 100000 == 0) Console.WriteLine("{0}: {1}", n, sum / n);
}
}
}
double avg = sum / n;
Console.WriteLine(avg);
}

static long Gcd(long a, long b)
{
long x = a;
long y = b;
while (x > 0)
{
long t = y % x;
y = x;
x = t;
}
return y;
}
}
}

For Claim 1, here is generalization of the answer given by @KBDave that I could come up with. All the ingredients of the proof are present in his answer thence I am not repeating them, instead I am just stating the results.

Let $$(a,b,c)$$ be a Pythagorean triplet, not necessarily primitive, such that $$f(a,b,c) = g\left(\frac{p}{q}\right)$$ for some positive integers $$q > p$$. Let $$\mu_n(a,b,c)$$ be the mean value of $$f\left(a,b,c\right)$$ for the first $$n$$ triplets when arranged in increasing order of $$(q,p)$$ without repetition. If $$g(x)$$ is Riemann integrable in $$(0,1)$$ then,

$$\lim_{n \to \infty}\mu_n(a,b,c) = \int_{0}^1 g\left(x\right)dx.$$

The key difference is that condition on primitive triplets is relaxed since uniform distribution holds with non primitive triplets if there is no repetition.

An application: Taking $$f(a,b,c) = bc/a^2$$ it implies that on an average the area of the rectangle formed by the two perpendicular sides of a Pythagorean triangle is $$1 - \log 2 \approx 30.7\%$$ of the area of the square formed by the hypotenuse.