Exploring the world through writing.
by Emmanuel Bakare
Title is inspired by a recent Netflix watch: The Secret Diary of a Call Girl
Dearest Gentle Reader, when I was in primary school some 10+ years that I can’t accurately calculate again (the irony of it all), I had some assignment that involved calculating a single value out a pythagorean triple, two of the values were provided for ease.
However, one particular case did not appear properly as the page had folded during print and messed up the value leaving me with only one value needing to find the other two.
This article is based on me reminiscing ecstatically on a Friday night the experience I had figuring it out over a decade ago: how does one find the remaining two elements if given one element in a pythagorean triple?
Pythagoras theorem is applied when computing one end of the three sides of a right-angled (90 degree) triangle.
A pythagorean triple is basically three elements (a, b, c) that satisfy:
\[a^2 + b^2 = c^2\]Natural numbers are all positive numbers excluding 0. This defines a metric system we can understand representing what a valid triangle would be constrained by. Therefore, all numbers for the start of this exercise will be bounded within the natural number space.
\[ \forall b \in {\displaystyle \mathbb {N} } \]
\(a\) will represent either the adjacent or opposite, it does not matter which and \(c\) will be the hypotenuse/diagonal. To ease out the discussion in later parts of this article, these will exist in the positive real number space.
\[ \forall a,c \in {\displaystyle \mathbb {R} } \ni \{a \geq 1 \;and\; c > a\} \]
As earlier noted, a pythagorean expression is represented by
\[a^2 + b^2 = c^2\]If we take any edge of the triangle asides the hypotenuse, the subject of the formula we arrive at is:
\[b^2 = c^2 - a^2\]Factorising the expression leads to:
\[b^2 = (c + a) * (c - a)\]Whenever, we have expressions in this form, we can take a factorization similar to computing the factors of a number. In this case, I factorise the expression to satisfy the equality as such:
\[c + a = b^2\] \[c - a = 1\]In doing so, I also define some expression that assumes there is a minimum distance \(k\) which is a whole positive number that is based on the difference of c and a.
\[ \forall k \in {\displaystyle \mathbb {N} } \ni k: k = c - a \]
In this case, we start off with 1 between the hypotenuse and the opposite. This will be pivotal in later exercises on defining what I call a “pythagorean distance” which I refer to as \(k\).
For this example with a “pythagorean distance” of 1, we will sum the expression to eliminate \(a\) and compute the expression for the hypotenuse.
\[c + a = b^2\] \[c - a = 1\]This expands to the following expression for calculating the hypotenuse of a pythagorean triple.
\[c = \frac{1}{2} (b^2 + 1)\]Doing the same with \(a\) gives
\[a = \frac{1}{2} (b^2 - 1)\]However, in using this formula, we must consider the earlier equalities:
\[c + a = b^2\] \[c - a = 1\]When considering the equalities, we must enforce that \(c + a > c - a\). This is because in our natural number space without 0, we cannot have an addition greater or equal to a subtraction.
Substituting that \(c + a = \frac{b^2}{k}\) and \(k = c - a = 1\), we have that \(b ^ 2 > 1\), implying \(b > 1\)
\[ \forall a,c \in {\displaystyle \mathbb {N} }, c+a > c-a \]
\[ \therefore \frac{b^2}{k} > k \]
\[ \therefore b^2 > k^2 \]
\[ \therefore b > k \]
Now, let’s test our formula with some simple math and python.
NOTE: The code down here is better than spaghetti but pasta is pasta :-P
import math
from fractions import Fraction
distances = 100
n = 100
def csv_print(*args, log):
log.append(','.join(map(str, args)))
# print(*args, sep=",")
for k in range(1, distances+1):
data = []
data_fractions = []
csv_print("a", "b", "c", log=data)
csv_print("a", "b", "c", log=data_fractions)
for b in range(n+1):
if b <= k:
continue
c = (1/2) * (math.pow(b, 2) / k + k)
a = (1/2) * (math.pow(b, 2) / k - k)
is_triple = math.pow(c, 2) == math.pow(a, 2) + math.pow(b, 2)
csv_print(a, b, c, log=data)
csv_print(Fraction(a), Fraction(b), Fraction(c), log=data_fractions)
with open(f"pythagorean-triple-csv-generator_{k}.csv", 'w') as csvfile:
csvfile.write('\n'.join(data))
# I do this to handle issues with precision handling but it's not great in python
# reason: is_triple = math.pow(c, 2) == math.pow(a, 2) + math.pow(b, 2)
# is_triple will show false due to precision mismatch on the power and not be correct
# I have checked and the values are fine, this will be my suffering for using python, lol
with open(f"pythagorean-triple-csv-generator_fractions_{k}.csv", 'w') as csvfile:
csvfile.write('\n'.join(data_fractions))
As you will see in the table, we now have a functioning way to calculate pythagorean triples for any number \(b\) within our natural number space.
a | b | c |
---|---|---|
1.5 | 2 | 2.5 |
4.0 | 3 | 5.0 |
7.5 | 4 | 8.5 |
12.0 | 5 | 13.0 |
17.5 | 6 | 18.5 |
24.0 | 7 | 25.0 |
31.5 | 8 | 32.5 |
40.0 | 9 | 41.0 |
49.5 | 10 | 50.5 |
60.0 | 11 | 61.0 |
71.5 | 12 | 72.5 |
84.0 | 13 | 85.0 |
97.5 | 14 | 98.5 |
112.0 | 15 | 113.0 |
127.5 | 16 | 128.5 |
144.0 | 17 | 145.0 |
161.5 | 18 | 162.5 |
180.0 | 19 | 181.0 |
199.5 | 20 | 200.5 |
In this example, you can realise that only the odd values have whole pythagorean triples with the even values of \(b\) violating our natural number space requirements. In the next sample, we will work through variants of the established pythagorean distance vector \(k\) in fixing these cases.
In our previous example, we have established the formula works and we will arrive at pythagorean triples with a distance of 1 established by \(k = c - a\). See the table above to validate this.
However, we have even numbers that do not express their triples as whole numbers. This can be fixed by increasing our pythagorean distance vector \(k\) to 2.
Let us start again from our factorization of
\[b^2 = (c + a) (c - a)\]Let’s take the factors to be fractional in this case where they are divided and increased by 2.
\[c + a = \frac{b^2}{2}\] \[c - a = 2\]Solving for c gives the following outcome for the simultaneous equation:
\[c + a = \frac{b^2}{2}\] \[c - a = 2\]We arrive finally at
\[c = \frac{1}{2} (\frac{b^2}{2} + 2)\]Solving for a also gives
\[a = \frac{1}{2} (\frac{b^2}{2} - 2)\]Using our fancy script, we regenerate the values for our table and we now have the opposite case with even values giving whole number and odd values giving fractional numbers.
a | b | c |
---|---|---|
1.25 | 3 | 3.25 |
3.0 | 4 | 5.0 |
5.25 | 5 | 7.25 |
8.0 | 6 | 10.0 |
11.25 | 7 | 13.25 |
15.0 | 8 | 17.0 |
19.25 | 9 | 21.25 |
24.0 | 10 | 26.0 |
29.25 | 11 | 31.25 |
35.0 | 12 | 37.0 |
41.25 | 13 | 43.25 |
48.0 | 14 | 50.0 |
55.25 | 15 | 57.25 |
63.0 | 16 | 65.0 |
71.25 | 17 | 73.25 |
80.0 | 18 | 82.0 |
89.25 | 19 | 91.25 |
99.0 | 20 | 101.0 |
We also notice that in this even case, the odd sample for 2 in the earlier table 1.5,2,2.5
when multiplied by 2 gives us the even values 3,4,5
for the now established whole value of 2 in the even table.
This is an occurrence we will discuss later in this blog, pythagorean triples can be commutative where multiples of the linear values also correlate to the outcome of the quadratic expressions.
When thinking about pythagorean triples, we usually have a hard time figuring out a pattern. However, this simplified when you consider there is a trick to it.
With the single value \(b\) which can exist with any distance from \(a\) and \(c\), \(a\) and \(c\) will always have a fixed distance from each other.
With this, you arrive at a conclusion where the triples can be established with some pythagorean distance \(k\) such that all the members of this threesome satisfy each other (lol!)
\[ \forall b \in {\displaystyle \mathbb {N} }, \exists \;a \;,\; c \in {\displaystyle \mathbb {R} } \]
\[forming \;a \;pythagorean \;triple \;\ni \; k \in {\displaystyle \mathbb {N} } \; \{k = c - a \} \]
\[ \therefore c = \frac{1}{2} (\frac{b^2}{k} + k) \]
\[ \therefore a = \frac{1}{2} (\frac{b^2}{k} - k) \]
The expression above forms the universal pythagorean triple calculator based on some distance, this therefore implies that a single value \(b\) can produce multiple pythagorean triples dependent on what distance you apply.
Taking \(k = 3\) as we have done for 1 and 2, we arrive at the same outcome. 9 for example produces 12 and 15 here whilst it produced 40 and 41 in the table for k=1.
a | b | c |
---|---|---|
1.1666666666666665 | 4 | 4.166666666666666 |
2.666666666666667 | 5 | 5.666666666666667 |
4.5 | 6 | 7.5 |
6.666666666666666 | 7 | 9.666666666666666 |
9.166666666666666 | 8 | 12.166666666666666 |
12.0 | 9 | 15.0 |
15.166666666666668 | 10 | 18.166666666666668 |
18.666666666666668 | 11 | 21.666666666666668 |
22.5 | 12 | 25.5 |
26.666666666666668 | 13 | 29.666666666666668 |
31.166666666666664 | 14 | 34.166666666666664 |
36.0 | 15 | 39.0 |
41.166666666666664 | 16 | 44.166666666666664 |
46.666666666666664 | 17 | 49.666666666666664 |
52.5 | 18 | 55.5 |
58.666666666666664 | 19 | 61.666666666666664 |
65.16666666666667 | 20 | 68.16666666666667 |
From here, we have established a formula to calculate any pythagorean triple within the real number space, however satisfying that the numbers are in the natural number space is experimental and I cover my approach to defining a boundary at the end of this article.
Within the same pythagorean distance \(k\), you will find that several series of digits repeat. This means that pythagorean triples repeat within different sets as multiples.
For example, within \(k=4\), we get the following sequence
a | b | c |
---|---|---|
1.125 | 5 | 5.125 |
2.5 | 6 | 6.5 |
4.125 | 7 | 8.125 |
6.0 | 8 | 10.0 |
8.125 | 9 | 12.125 |
10.5 | 10 | 14.5 |
13.125 | 11 | 17.125 |
16.0 | 12 | 20.0 |
19.125 | 13 | 23.125 |
22.5 | 14 | 26.5 |
26.125 | 15 | 30.125 |
30.0 | 16 | 34.0 |
34.125 | 17 | 38.125 |
38.5 | 18 | 42.5 |
43.125 | 19 | 47.125 |
48.0 | 20 | 52.0 |
Within this sequence, we can use this value:
2.5,6,6.5
If we multiply this value by 2 to remove the fractions, we will get another pythagorean triple
5,12,13
However, you will notice 12 has another set of pythagorean triples different from what we would expect
16,12,20
When pythagorean triples run, you can have multiple sets within the natural number space with different pythagorean distances. In this case, both examples have \(k\) with values of 8 and 4 respectively when \(b=12\).
Taking another from \(k=2\) and multiplying it by 2 for example gives one example on the table
3,4,5 -> 6,8,10
What you will find in examining pythagorean triples using the pythagorean distance approach is that triples will repeat and they are multiplicative reflections of each other. Some will exist within the same distance if the distance repeats or extend into other versions of \(k\).
In succession to the chapter on repeating triples, you will find that getting new pythagorean triples is a matter of computing prime versions of \(b\) and establishing multiples of the related triple combinations.
All of this can be automated using the Sieve of Eratosthenes or better yet, Prime factorization using the square root method
To establish whole triples, one must arrive a case where \(c\) and \(a\) are both odd or even.
This therefore means that adding both values must result in a positive value before the addition of k.
We have established that: \(c + a = \frac{b^2}{k}\)
Therefore, to arrive at whole triples, \(\frac{b^2}{k}\) must be even if k is even or odd if k is odd.
The table below where \(k=5\) showcases this summary
a | b | c | k | b^2/k |
---|---|---|---|---|
1.1 | 6 | 6.1 | 5 | 7.2 |
2.4000000000000004 | 7 | 7.4 | 5 | 9.8 |
3.9000000000000004 | 8 | 8.9 | 5 | 12.8 |
5.6 | 9 | 10.6 | 5 | 16.2 |
7.5 | 10 | 12.5 | 5 | 20.0 |
9.6 | 11 | 14.6 | 5 | 24.2 |
11.9 | 12 | 16.9 | 5 | 28.8 |
14.399999999999999 | 13 | 19.4 | 5 | 33.8 |
17.1 | 14 | 22.1 | 5 | 39.2 |
20.0 | 15 | 25.0 | 5 | 45.0 |
23.1 | 16 | 28.1 | 5 | 51.2 |
26.4 | 17 | 31.4 | 5 | 57.8 |
29.9 | 18 | 34.9 | 5 | 64.8 |
33.6 | 19 | 38.6 | 5 | 72.2 |
37.5 | 20 | 42.5 | 5 | 80.0 |
41.6 | 21 | 46.6 | 5 | 88.2 |
45.9 | 22 | 50.9 | 5 | 96.8 |
50.4 | 23 | 55.4 | 5 | 105.8 |
55.1 | 24 | 60.1 | 5 | 115.2 |
Decade long interests in math can have long-lasting benefits such as sleep deprivation and hyper-focus during these kinds of nostalgic moments.
I found writing this exciting and I hope you all as my “Dearest Gentle Readers” found this gossip amusing.
If you enjoyed this, I write about math problems I remember from day to day, one interesting being this optimisation case for Project Euler, Problem 25. Do send me those you also come across day-to-day.
Code for the simulations done for this article can be found here: https://github.com/tiemma/unravelling-mathematical-threesomes and a summary of mathematical symbols used in this article can be found here: https://en.wikipedia.org/wiki/Glossary_of_mathematical_symbols
tags: pythagoras - quadratic formula - pythagorean triples