7. New Experiments: Sum of Squares and Plotting II

I hope you had a wonderful time during the holiday break. In today’s lecture, we will revisit the problem on sum of squares of integers, which we began to explore just before the holiday break. The problems is as follows:

Question: Given that a and b are integers, what integers n can be written in the form n=a^2+b^2?

Here are a cases that do and do not work.

  • 2 = 1^2+1^2 works;

  • 3 does not work, since we only allow integers.  1+1 is too small, 1^2+2^2=5 is too big;

  • 4 actually does work, because we allow 4 = 0^2+2^2. (That’s just one of our rules; you could play a different game if you wanted.);

  • That means 1=1^2+0^2 works.

  • 5 works.

And so forth. In our last lecture, we were able to pose the following questions relating to the sum of squares:

  • Which positive integers can be written as a sum of two squares?

  • Which ones cannot?

  • Which positive integers can be written as a sum of squares of it factors?

  • Can there be a formula for expressing n as the sum of two positive square numbers?

  • Which numbers can be written as a sum of squares of 2 prime numbers?

  • These numbers that can be written as a sum of two squares, are they odd or even?

  • Is the sum of squares even or odd?

  • Given a and b are prime, is the sum of their squares, a^{2}+b^{2} prime?

  • Can the square roots of numbers be written in any other form aside from x^{2} + 0^{2}?

  • Is there more than one way to get the n, and if they is, what’s the relationship between the a, b and n.

In our last lecture, we started by first tried working with pens and paper. We tried by listing those positive integers n ranging from 1 to 50 that can be written as a sum of squares and those that can not be written.

What possible Python buitin data structure(s) do you think will be best in storing the numbers that can be written?

my_list_database = [0, 1, 4, 5]

What if, in addition to the possible positive integers that can we can write as the sum of two squares, we also want to know the number of ways that they can be written. What Python builtin data structure(s) do you think will be suitable in this case?

Let us create a database of some of the numbers that can be written starting with those that we tried with pens and paper.

number_of_ways = [1, 2, ]
sum_of_square_database = {0: [(0,0)], 1: [(1,0), (0,1)], 2:[(1,1)]}; sum_of_square_database
{0: [(0, 0)], 1: [(1, 0), (0, 1)], 2: [(1, 1)]}
sum_of_square_database[4] = [(0,2), (2, 0)]
sum_of_square_database
{0: [(0, 0)], 1: [(1, 0), (0, 1)], 2: [(1, 1)], 4: [(0, 2), (2, 0)]}
for k in sum_of_square_database:
    print(k)
0
1
2
4
list(iter(sum_of_square_database))
[0, 1, 2, 4]
sum_of_square_database
{0: [(0, 0)], 1: [(1, 0), (0, 1)], 2: [(1, 1)], 4: [(0, 2), (2, 0)]}
sum_of_square_database = {}
for a in range(10):
    for b in range(10):
        m = a^2 + b^2

After sometime you will want to think of an effective way of doing this by using some Python programming construct? What could be your possible effective solution?

Hopefully, by now you should have a fair amount of data in sum_of_square_database. Let us now begin exploring the questions we posed regarding the sum of two squares by querying the database we have created.

After a while, we will come back and I will ask you about possible ways to rethink the problem on the sum of squares.

Can you think of a way to solve this problem? Hint: What do you know about equations of this form :math:`n = a^{2} + b ^{2}`?

This brings up the question of how to do such plotting in the first place? We will look at this in more detail in the next Section.

7.1. More Plotting and Graphics in Two Dimensions

There is absolutely no way we could cover all the graphics in SageMath (or the program that does it for SageMath, matplotlib) in one day, or even a week. We will look at a bunch of different resources you have access to, and see lots of different plot types. As we go through these resources, think of how they will be of in solving our new experiment or where you could have used them some time back in your academic career. I definitely do not know everything about the plotting command. Nevertheless, you may interrupt me with your question so that we can explore the solution together.

Remember, you should feel free to stop listening for a while if you can want to try something out!
Once we’ve seen enough examples, please either start using SageMath to explore the sums of squares, or try to recreate your favorite graphic using SageMath!