Ask Your Question

How do you check if a lattice contains a coordinate?

asked 2021-04-29 21:36:35 +0200

ant314159265 gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-29 22:11:53 +0200

slelievre gravatar image

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
sage: v2 in L
sage: vector((0, 0)) in L
sage: vector((1, 0)) in L
sage: vector((0, 1)) in L
sage: vector((1, 1)) in L
sage: vector((2, 0)) in L
sage: vector((1/2, 1)) in L
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2021-04-29 21:36:35 +0200

Seen: 308 times

Last updated: Apr 29 '21