# How do you check if a lattice contains a coordinate?

Suppose I have an integer lattice $L\subset\mathbb{Z}^2$ generated by $v_1$ and $v_2$. How do I check if $(x,y)\in L$?

I can easily create the lattice:

from sage.modules.free_module_integer import IntegerLattice
v1 = [3,4]
v2 = [4,5]
M = [v1,v2]
IL = IntegerLattice(M)


but nowhere in the documentation can I find a command to check for inclusion. I would like a solution that generalizes to lattices of any rank.

edit retag close merge delete

Sort by » oldest newest most voted

Use in to check membership.

The check will work if the vector is constructed with vector, not if it is a list or tuple.

Below are some examples.

sage: from sage.modules.free_module_integer import IntegerLattice
sage: v1 = vector((3, 4))
sage: v2 = vector((4, 5))
sage: M = [v1, v2]
sage: L = IntegerLattice(M)

sage: L
Free module of degree 2 and rank 2 over Integer Ring
User basis matrix:
[-1  0]
[ 0  1]

sage: v1 in L
True
sage: v2 in L
True
sage: vector((0, 0)) in L
True
sage: vector((1, 0)) in L
True
sage: vector((0, 1)) in L
True
sage: vector((1, 1)) in L
True
sage: vector((2, 0)) in L
True
sage: vector((1/2, 1)) in L
False

more