Explain the logic behind the Pythagorean theorem.