Pythagorean theorem by dissecting two squares into a third

In the last post in which I was discussing the problem of cutting a polygon into pieces I wrapped up the final argument by simply stating the fact that two squares can be cut into pieces and rearranged into another square rather than prove or demonstrate it. I didn’t bother giving the actual proof or demonstration because a) it was late when I finished the post and b) there are better explanations of the proof out there than the one I can come up with.

The ‘I’m bad at coming up with the best schemes for explaining things’ -thing is of course true one day later but in sketching a program which would do dissections in an automated way I ended up making some Tikz pictures anyways so I thought I might as well share them for completeness.

So given two squares the larger one can be cut into three parts and the smaller one into two parts and the pieces can be combined into a square which has the sum of their areas. As I said then this is related to Pythagorean theorem and the actual construction can be seen here. I apologize for my terrible choice of colors but as to finding the actual cuts you can essentially just place the smaller squares next to each other and cut out two equal straight triangles which corresponds to the triangle in the Pythagorean theorem. Here is the very inoptimized Tikzcode for generating the triangle and squares. \a and \b determines the sizes of the squares.

\begin{tikzpicture}[very thick,scale = 1]
\pgfmathsetmacro{\a}{3}; %Side of bigger square
\pgfmathsetmacro{\b}{2};%Side of smaller square

\draw [fill = yellow] (0,0) -- (\b, 0) -- (0, \a) -- (0,0);

\draw [fill = red](-\a, 0) -- (\b - \a, 0) -- (-\a, \a) -- (-\a,0);
\draw [fill = blue](\b - \a, 0) --(0,{\b * (1 - \b / \a)}) -- (0,0) -- (\b - \a,0);
\draw [fill = green](\b - \a, 0) --(0,{\b * (1 - \b / \a)}) -- (0, \a) -- (-\a,\a) -- (\b - \a,0);

\draw [fill = cyan](0,0) -- (0,{\b * (1 - \b / \a) - \b}) -- (\b,0) -- (0,0);
\draw [fill = magenta](0,{\b * (1 - \b / \a) - \b}) -- (0,-\b) -- (\b,-\b) -- (\b,0) -- (0,{\b * (1 - \b / \a) - \b});

\draw [fill = red](\a, \b) -- (\a + \b, \b) -- (\a, \a + \b) -- (\a,\b + \b);
\draw [fill = blue] (0,\a) -- (\a - \b,{\a + \b * (1 - \b / \a)}) -- (\a - \b, \a) -- (0,\a);
\draw [fill = green](\b, 0) --(\a,{\b * (1 - \b / \a)}) -- (\a, \a) -- (0,\a) -- (\b,0);

\draw [fill = cyan](\a,\b) -- (\a,{\b * (1 - \b / \a)}) -- (\a + \b,\b) -- (\a,\b);
\draw [fill = magenta] (\a - \b,{\a + \b * (1 - \b / \a)}) -- (\a - \b, \a) -- (\a,\a) -- (\a, \a + \b) -- (\a - \b,{\a + \b * (1 - \b / \a)});
\end{tikzpicture}