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 out 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.