.. Created by Adam Cunnningham on Fri June 3 2016. **Primitive Pythagorean Triples** ================================= *Pythagorean triples* are positive integer solutions (a, b, c) to the equation a\ :sup:`2` + b\ :sup:`2` = c\ :sup:`2`. *Primitive Pythagorean Triples* are those for which a, b, and c are relatively prime (have no common divisor greater than 1). Report Description ------------------ The report consists of the following exercises. Once you have the exercises complete, write a report containing your results and conclusions. Refer to the class notes for the structure of the reports and what they should contain. **Exercise 1. Greatest Common Divisor** Write a function ``mygcd(a, b)`` that returns the greatest common divisor of two positive integers a and b. Test this function to make sure that it is working correctly. **Exercise 2. Perfect Squares** Write a function ``is_square(x)`` that returns True if x is a perfect square and False otherwise. Test this function to make sure that it is working correctly. **Exercise 3. Generate Primitive Pythagorean Triples** Generate all Primitive Pythagorean Triples for a, b :math:`\leq` 5000 (Just generate them - you **don't** need to print them all out.) **Exercise 4. Plot and Analyze Your Results** See if there is any discernible structure in the Primitive Pythagorean Triples. Hints and Suggestions for the Report ------------------------------------ Writing the ``mygcd`` and ``is_square`` Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - It's a good idea to use **print** functions inside your functions to check that code is working as expected. For example, printing out a and b inside the **while** loop in your ``mygcd`` function will show the algorithm working step-by-step. These statements can be commented out later using #. Generating the Primitive Pythagorean Triples ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Use ``mygcd(a, b) == 1`` to check if a and b are relatively prime. - Use ``is_square(a**2 + b**2)`` to test if a\ :sup:`2` + b\ :sup:`2` is a perfect square. - Test your code using small numbers first, maybe a, b :math:`\leq` 100. Make sure the code is working on these small numbers before moving on to bigger numbers. Plotting and Analyzing the Results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Generate graphs using Matplotlib **plot** to look for patterns. - *Look* at the Primitive Pythagorean Triples as well by printing some out. Are there any kinds of mathematical regularity that you can see? Can you find reasons for any of these regularities?