Section 13.1 Some First Ideas
ΒΆSubsection 13.1.1 A first pattern
ΒΆLet's assume you've done some exploration on your own. Here's a first pattern that you may have noticed, similarly to patterns in the past.Fact 13.1.1.
If nβ‘3 (mod 4), then n is not writeable as a sum of squares.
Proof.
You should be able to prove this pretty easily based on things you already know about squares modulo 4. (See Exercise 13.7.1)
xxxxxxxxxx
two_squares(29)
xxxxxxxxxx
two_squares(21)
Fact 13.1.2.
There are nβN where nβ‘0,1,2 (mod 4) but which are not representable as a sum of two squares.
Proof.
Show that \(12\text{,}\) \(21\text{,}\) and \(6\) are not. (See Exercise 13.7.2.)
xxxxxxxxxx
def _(n=29):
try:
a,b = two_squares(n)
pretty_print(html("We can write ${0}={1}^2+{2}^2$".format(n,a,b)))
except ValueError:
pretty_print(html("${0}$ is not a sum of two squares".format(n)))
Sage note 13.1.3. Handling errors.
Most computer languages have a way to βhandleβ errors if we don't want to think of them as errors. In Python, this is the try
/except
syntax you see above. Basically, we are trying to use the two squares command, but if it hiccups, we instead just print a nice message.
Remark 13.1.4.
We have already addressed a very special case of writing numbers as a sum of squares. In fact, in Theorem 3.4.6 we saw a precise characterization of when a perfect square is a sum of two squares. We will mention this again briefly in Subsection 14.2.2.
Subsection 13.1.2 Geometry
ΒΆNext, we can interpret this question very differently, relying on our geometric intuition. Figure 13.1.5 helps us visualize the problem.
xxxxxxxxxx
def _(n=(5,list(range(100)))):
viewsize=ceil(math.sqrt(n))+2
g(x,y)=x^2+y^2
p = implicit_plot(g-n, (-viewsize,viewsize), (-viewsize,viewsize), plot_points = 100)
lattice_pts = [[i,j] for i in [-viewsize..viewsize] for j in [-viewsize..viewsize]]
plot_lattice_pts = points(lattice_pts,rgbcolor=(0,0,0),pointsize=2)
curve_pts = [coords for coords in lattice_pts if g(coords[0],coords[1])==n]
if len(curve_pts)==0:
show(p+plot_lattice_pts, figsize = [5,5], xmin = -viewsize, xmax = viewsize, ymin = -viewsize, ymax = viewsize, aspect_ratio=1)
else:
plot_curve_pts = points(curve_pts, rgbcolor = (0,0,1),pointsize=20)
show(p+plot_lattice_pts+plot_curve_pts, figsize = [5,5], xmin = -viewsize, xmax = viewsize, ymin = -viewsize, ymax = viewsize, aspect_ratio=1)
Question 13.1.6.
Which circles around the origin do (or do not) have lattice points?
If a circle has lattice points, how many does it have?
Subsection 13.1.3 Connections to some very old mathematics
ΒΆThe following identity was, separately, already known to Diophantus (remember Diophantine equations?) around 250, to Brahmagupta (about whom more in Section 15.6) around 600, and to Leonardo of Pisa (known also as Fibonacci) around 1250.Fact 13.1.7. Brahmagupta-Fibonacci identity.
Proof.
Multiply and cancel; see Exercise 13.7.6.
Fact 13.1.8.
Products of numbers writeable as sums of squares can also be written as sums of squares!
Proof.
Use 13.1.7 above.
xxxxxxxxxx
def _(m=(13,[0..100]),n=(8,[0..100])):
try:
a,b = two_squares(m)
c,d = two_squares(n)
pretty_print(html(r"We know we can write ${6}={0}\cdot {1}$ as $({2}^2+{3}^2)({4}^2+{5}^2)$".format(m, n, a, b, c, d, m*n)))
pretty_print(html(r"But it is also writeable as $({0}\cdot{1}-{2}\cdot{3})^2 + ({0}\cdot{3}+{1}\cdot{2})^2 = {4}^2+{5}^2={6}$".format(a, c , b , d , abs(a*c-b*d), a*d+b*c,m*n)))
except ValueError:
pretty_print(html("Please pick numbers that are both writeable as a sum of two squares"))