Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Created February 16, 2022 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gro-Tsen/b3e79b7ef8dd04fb11e8fbc3118b9eda to your computer and use it in GitHub Desktop.
Save Gro-Tsen/b3e79b7ef8dd04fb11e8fbc3118b9eda to your computer and use it in GitHub Desktop.
# Try to find an approximate pentagon in a square lattice:
# For this, we use LLL to try to find (v_0,v_1,v_2,v_3) four
# integer-valued vectors of size 2 such that v_1 is close to R(v_0),
# v_2 is close to R^2(v_0) and v_3 is close to R^3(v_0), where R is
# rotation by 2*pi/5, and v_0 is not too large.
# How much weight to give to the size of the approximation:
weight = 1/200
# We try to find a small vector in the image of the matrix m below,
# acting on integer-valued column vectors, i.e., on the lattice
# generated by the columns of m:
m = Matrix(RR,8,8,[[cos(2*pi/5),sin(2*pi/5),cos(4*pi/5),sin(4*pi/5),cos(6*pi/5),sin(6*pi/5),weight,0],[-sin(2*pi/5),cos(2*pi/5),-sin(4*pi/5),cos(4*pi/5),-sin(6*pi/5),cos(6*pi/5),0,weight],[-1,0,0,0,0,0,0,0],[0,-1,0,0,0,0,0,0],[0,0,-1,0,0,0,0,0],[0,0,0,-1,0,0,0,0],[0,0,0,0,-1,0,0,0],[0,0,0,0,0,-1,0,0]]).transpose()
# Gram matrix (quadratic form on the lattice):
mq = m.transpose() * m
# Perform LLL (the columns of u give the inputs to m, i.e., m*u is the
# LLL basis):
u = mq.LLL_gram()
# The vectors we found:
vecs = [(ZZ^2)((u[i*2][0],u[2*i+1][0])) for i in range(4)]
# The vertices of the pentagon:
pts = [(ZZ^2)(sum([vecs[j] for j in range(i)])) for i in range(5)]
# Draw it:
sum([line([pts[i],pts[(i+1)%5]]) for i in range(5)]).show(dpi=192,aspect_ratio=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment