<s>[INST] Given two pythagorean triples, generate another I don't know if this has been asked before, but I could not find any existing answer.
I noticed that for any pair of primitive pythagorean triples (not necessarily distinct), let's say:
a² + b² = c²
d² + e² = f²

Then there is at least another primitive triple where:
g² + h² = (cf)²

And there are 2 if the starting triples are distinct.
So, for example:
(3,4,5) and (5,12,13) -> (16, 63, 65) and (33, 56, 65)
(5,12,13) and (8,15,17) -> (21, 220, 221) and (140, 171, 221)
(3,4,5) (5,12,13) (8,15,17) -> (817,744,1105) (943,576,1105) (1073,264,1105) (1104,47,1105)
(3,4,5) and (3,4,5) -> (7,24,25)

I think there is an explanation for that, a property of pythagorean triples, or in general of diophantine equations.
Is it true in every case? Is there a way to calculate the two legs of the resulting triple(s)?
 [/INST] You can always find new triplets this way, although they are not necessarily primitive. This is just the Brahmagupta–Fibonacci identity in action.
For example, for $(5,12,13)$ and $(8,15,17)$, the identity states that:
$$(5\cdot8 - 12\cdot15)^2 + (5 \cdot 15 + 12 \cdot 8)^2 = (-140)^2 + (171)^2$$
$$= (5\cdot8 + 12\cdot15)^2 + (5 \cdot 15 - 12 \cdot 8)^2 = (220)^2 + (-21)^2$$
$$= (5^2 + 12^2) (8^2 + 15^2) = 13^2 \cdot 17^2 = 221^2$$
When the starting triplets are the same, then $a=d, b=e$. Using the given identity, $(ad - be)^2 + (ae + bd)^2 = (a^2-b^2)^2 + (ab + ba)^2 = a^4+b^4-2a^2b^2+4a^2b^2$ $ = a^4 + b^4 + 2a^2b^2 = (a^2+b^2)^2 = (a^2+b^2)(d^2+e^2)$.
The other possibility is $(ad + be)^2 + (ae - bd)^2 = (a^2 + b^2)^2 + (ab - ba)^2 = (a^2 + b^2)^2$, where one of the numbers of the new triplet is $0$. This explains why there is only one non-trivial triplet in this case.
Here is a counterexample that they are not always primitive. With $(13,84,85)$ and $(16,63,65)$, $ad+be, ae-bd$ gives $(5500,525,5525)$ which are all divisible by $25$. A further conjecture could be made on if $c,f$ are both divisible by $k$, then whether the lowest common divisor would be $k^2$.
</s>