Section 3.3 Positive Integer Lattice Points
Question 3.3.1.
Assume there exists a solution (hence infinitely many) to ax+by=c. How many such solution pairs (x,y) have x and y both positive?

xxxxxxxxxx
def _(a=slider(1,20,1,1), b=slider(1,20,1,1), c=slider(1,20,1,4)):
ym = c/b + 1
xm = c/a + 1
p = plot(-(a/b)*x+c/b,-1,xm, plot_points = 200)
lattice_pts = [[i,j] for i in [0..xm] for j in [0..ym]]
plot_lattice_pts = points(lattice_pts,rgbcolor=(0,0,0), pointsize=2)
if mod(c,gcd(a,b))==0:
line_pts = [coords for coords in lattice_pts if (coords[0]>0) and (coords[1]>0) and (a*coords[0]+b*coords[1]==c)]
if len(line_pts)==0:
pretty_print(html( 'Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html( 'No positive lattice points at all!'))
show(p+plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
else:
plot_line_pts = points(line_pts, rgbcolor = (0,0,1), pointsize=20)
pretty_print(html('Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html('Number of positive lattice points = ' + str(len(line_pts))))
show(p+plot_lattice_pts+plot_line_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
else:
pretty_print(html('Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html('No positive lattice points at all!'))
show(p+plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
x+y=4, x+y=5, x+y=6, …
2x+y=4, 2x+y=5, 2x+y=6, …
2x+2y=4, 2x+2y=5, 2x+2y=6, …
3x+y=4, 3x+y=5, 3x+y=6, …
Subsection 3.3.1 Solution ideas
If you think about the question a little more carefully together with the picture, you may realize that we are really asking about how many integer lattice points lie between the intercepts. So one way to think about an answer would involve the distance between solutions. To be concrete, let's assume that the equation is ax+by=c, and gcd(a,b)=1. Then, using our technique from last time, from the solution (x0,y0) we get a new solution (x0+b,y0−a), so the distance between any two solutions is, by the Pythagorean Theorem,How many times does that distance fit between the intercepts of the line?
The intercepts are ca and cb, respectively.
-
Using the Pythagorean Theorem again, we see that the whole length available is
√(ca)2+(cb)2=cab√a2+b2. The ratio of this total length and the length between solutions is thus cab.
There is no guarantee that cab is an integer! In fact, it usually won't be. For instance, with 2x+3y=10, 102⋅3≈1.67. So should the number of points be bigger than or less than this?
Secondly, even so it's not clear what the precise connection between cab and the actual number of points is. 2x+3y=5 has one, and 2x+3y=7 has one, but 2x+3y=6 doesn't. Yet cab is about equal to one for all three of these. In fact, the number of points is thus not even monotone increasing with respect to c increasing, which is rather counterintuitive.
Subsection 3.3.2 Toward the full solution
We can deal with each of these problems. To do so, we introduce a new function:Definition 3.3.3. Greatest integer function.
The greatest integer function (also called the floor function) is the function which takes a real number x and returns the largest integer below it (or equal to it). We notate it ⌊x⌋.
Example 3.3.4.
A few examples should suffice to understand it:
To take care of the integer problem, we will just consider n=⌊cab⌋, the greatest integer function applied to cab.
Secondly, we simply recognize that there isn't a nice formula. On average, we should expect n lengths between integer points along the line segment in question (and hence as many as n+1 lattice points, since a partition of n intervals has n+1 endpoints associated to it).
xxxxxxxxxx
def _(c=[5..12]):
a = 2
b = 3
ym = c/b + 1
xm = c/a + 1
p = plot(-(a/b)*x+c/b,-1,xm, plot_points = 200)
lattice_pts = [[i,j] for i in [0..xm] for j in [0..ym]]
plot_lattice_pts = points(lattice_pts,rgbcolor=(0,0,0),pointsize=2)
if mod(c,gcd(a,b))==0:
line_pts = [coords for coords in lattice_pts if (coords[0]>0) and (coords[1]>0) and (a*coords[0]+b*coords[1]==c)]
if len(line_pts)==0:
pretty_print(html('Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html('No positive lattice points at all!'))
show(p+plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
else:
plot_line_pts = points(line_pts, rgbcolor = (0,0,1),pointsize=20)
pretty_print(html('Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html('Number of positive lattice points = ' + str(len(line_pts))))
show(p+plot_lattice_pts+plot_line_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
else:
pretty_print(html('Solutions to $%sx+%sy=%s$:'%(str(a),str(b),str(c))))
pretty_print(html('No positive lattice points at all!'))
show(p+plot_lattice_pts, figsize = [5,5], xmin = 0, xmax = xm, ymin = 0, ymax = ym)
-
The easiest case is when just one of the intercepts is a lattice point. Beginning at that point, there is definitely room for the full n lengths to appear, and you're guaranteed to get n lattice points, because we just said the other intercept isn't a lattice point, so the nth one must appear before that point. So the formula is just plain old
n=⌊cab⌋.This will happen (where n=1) with 2x+3y=8 (or 9 or 10), for instance.
If neither c/a nor c/b is an integer, then you could get n or n+1 lattice points. There's no nice formula beyond this, and often examples will be like 2x+3y=7 with just one lattice point as ‘expected’. When the extra point ‘fits’ is in examples like the case 2x+3y=11, where we have 112⋅3−⌊112⋅3⌋ very close to one, and you do get ⌊112⋅3⌋+1=2 positive lattice points here.
-
Finally, it's also possible for ‘not enough’ lattice points to fit; for example, 2x+3y=12 jumps back down to ⌊122⋅3⌋−1=1 points! This situation (not reaching n points) can occur when both the x- and y-intercepts actually are lattice points, because the intercepts by definition do not have positive coordinates. So if c/a and c/b are both integers, then we get precisely
n−1=⌊cab⌋−1lattice points.