Interactive fun
Inspired by: https://crypto.katestange.net/lattice-tools/
Lattice + LLL + Fundamental mesh plot
@interact
def draw_lattice(v1x = input_box(label = "v1 x =", default = 1),
v1y = input_box(label = "v1 y =", default = 0),
v2x = input_box(label = "v2 x =", default = 0),
v2y = input_box(label = "v2 y =", default = 1),
box = 5, search = 10,
plot_LLL = True,
plot_C = True,
plot_F = True):
v1 = vector((v1x, v1y))
v2 = vector((v2x, v2y))
vecs = []
# Generate vectors
for i in range(-search,search):
for j in range(-search,search):
vecs.append(i*v1 + j*v2)
# Plot stuff
G = Graphics()
for p1 in vecs:
x1, y1 = p1
if x1 > -box and x1 < box and y1 > -box and y1 < box:
G += point(p1, color = 'green', size = 30)
G += line([p1, p1 + v2], linestyle = '--', alpha = .20)
G += line([p1, p1 + v1], linestyle = '--', alpha = .20)
G+= arrow((0, 0), v1, color = 'red', arrowsize = 2)
G+= arrow((0, 0), v2, color = 'red', arrowsize = 2)
G+= text('v1', v1 + .2 * v1, color = 'red')
G+= text('v2', v2 + .2 * v2, color = 'red')
# LLL
if plot_LLL:
v1_, v2_ = matrix([v1, v2]).LLL()
G+= arrow((0, 0), v1_, color = 'purple', arrowsize = 2)
G+= arrow((0, 0), v2_, color = 'purple', arrowsize = 2)
if plot_C:
G += circle(center = (0, 0), radius = norm(v1_) if norm(v1_) > norm(v2_) else norm(v2_), alpha = .5, color = 'purple')
# Fundamental mesh
if plot_F:
F = polygon([[0, 0], v1, v1 + v2, v2], color='red', alpha = .1)
G += F
G.show(axes = False, figsize = (7, 7))

Lattice + CVP

Q-ary plots
Last updated
Was this helpful?