What are the perfect squares for $a^2 + b^2$? I have been writing a python program to generate integers that satisfy the perfect root of $a^2 + b^2$ over large ranges of values using brute force loops. Are there direct generating equations to solve this problem?
Just to be clear, for example, $a = 16$ and $b=30$ form a perfect square, since $\sqrt{16^2+30^2}=34$. So is $a=1308$ and $b=3815$, and so on.
In my searching, I read how Euclid solved the Diophantine equations for pythagorean triples and I thought the method would apply to my situation.
I thought that if $a$, $b$, and $c$ satisfied the triple $a^2+b^2=c^2$, then $a^2+b^2$ is a perfect square and would be given by the same equations of Euclid. Namely,
$a=m^2-n^2$, $b=2mn$. And indeed, this is the case for $a=16$ and $b=30$ where $m=5$ and $n=3$. Success, I thought!
But there is no rational solution for $a=1308$ and $b=3815$ or any of the other $a,b$ pairs as per some fiddling on wolframalpha.
 A: The structure of Pythagorean triples is well-known. Let us consider the circle $x^2+y^2=1$ and a line with rational slope through $(1,0)$: by Vieta's theorem the second intersection with the circle is a point with rational coordinates, and if $P(x,y)\neq(1,0)$ is a point on the unit circle with rational coordinates the line joining $P$ with $(1,0)$ has a rational slope. By computing in a explicit way the non-trivial intersection between $x^2+y^2=1$ and a line through $(1,0)$ with slope $t\in\mathbb{Q}$ we get that

Every rational point $P(x,y)$ on $x^2+y^2=1$ is of the form $x=\frac{1-t^2}{1+t^2}, y=\frac{2t}{1+t^2}$ for some $t\in\mathbb{Q}\cup\{\infty\}$. 

Every rational point on $x^2+y^2=1$ is associated with a Pythagorean triple by
$$ \left(\frac{a}{c},\frac{b}{c}\right)\in S^1 \mapsto (a,b,c)\in\mathbb{Z}^3, a^2+b^2=c^2.$$
In particular:

Corollary: if $a,b,c$ are positive integers such that $a^2+b^2=c^2$, up to switching $a$ and $b$ we have
  $$ a = d(2pq),\quad b=d(p^2-q^2),\quad c=d(p^2+q^2) $$
  with $d\geq 1$, $p\geq q\geq 1$, $\gcd(p,q)=1$ and at least one number between $p,q$ being even.

This generates the whole set of Pythagorean triples, and the constraint $d=1$ gives the primitive pythagorean triples.
A: Euclid's formula generates primitive Pythagorean triples.  Your example, $b = 2 m n = 1308, a = m^2 - n^2 = 3815$ has no solution in integers because $\gcd(a,b) = 109$.  (Note that $b = 2 m n$ always has to be the even member of the pair.)  For primitive Pythagorean triples, $\gcd(a,b) = 1$.  The primitive triple with $a = 3815/109 = 35$ and $b = 1308/109 = 12$ is given by $m = 6, n = 1$.
To get all Pythagorean triples, use $a = g(m^2 - n^2), b = g(2 m n)$, where $g$ is the common factor of $a$ and $b$ and is allowed to range over all positive integers, and $m$ and $n$ range over all positive integers with $m > n$.
A: Yes. There are, in fact, ways to generate infinitely many pythagorean triples. Suppose we have $$a,b,c \in \mathbb N$$
METHOD 1: Let $a$ be some odd number. Then set
$$b=\frac{a^2-1}{2}$$
and set
$$c=\frac{a^2+1}{2}$$
Ta da! $a^2+b^2=c^2$!
METHOD 2: Let $a \ge 8$ be some doubly even number. Then set
$$b=\frac{a^2}{4}-1$$
and
$$c=\frac{a^2}{4}+1$$
Ta da! Even more pythagorean triples!
These are both proven to work easily; however, I have not figured out how to prove or disprove that all pythagorean triples can be generated by one of these two methods.
Does this help?
