ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 29 Apr 2021 21:36:35 +0200How do you check if a lattice contains a coordinate?https://ask.sagemath.org/question/56863/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.ant314159265Thu, 29 Apr 2021 21:36:35 +0200https://ask.sagemath.org/question/56863/Sagemath: Closest_vector not working on mxn matrix when m!=n?https://ask.sagemath.org/question/56336/sagemath-closest_vector-not-working-on-mxn-matrix-when-mn/ I want to solve the following closest vector problem: Given an mxn matrix A where A \in Z_q^n and a vector u, find the closest vector to u in the q-ary lattice spanned by A, that is in the lattice that contains all points y=(Az mod q) for some z \in Z_q^n. Do to do this, I implemented the following sage code.
import random
from sage.modules.free_module_integer import IntegerLattice
Q = 7
B = [[1,2],[4,5],[3,6],[5,2]]
R = Integers(Q)
MS = MatrixSpace(R, 4, 2)
A= MS(B)
N = A.change_ring(ZZ)
N = N.augment(Q * identity_matrix(4)) # To enforce calculation modulo q
L = IntegerLattice(N)
u = [1,2,3,4]
print(L.closest_vector(u))
From my understanding, this should work even though m!=n, because the vectors in the lattice spanned by the Basis N are still 4-dimensional. However, I am getting the following error:
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 6 by 6 dense matrices over Rational Field' and 'Ambient free module of rank 4 over the principal ideal domain Integer Ring'
What am I doing wrong?
latticestudentTue, 23 Mar 2021 18:21:05 +0100https://ask.sagemath.org/question/56336/Determine Two quadratic form is integer congruence (rational equivalent)?https://ask.sagemath.org/question/55294/determine-two-quadratic-form-is-integer-congruence-rational-equivalent/Fix $n \\geq 2$ and consider $A,B \\in \\operatorname{GL}(n,\\mathbb{Z}).$
We know that we have the Smith normal form.
One can find $U, V \\in \\operatorname{SL}(n,\\mathbb{Z})$ such that $A=UDV.$
Likewise for $B$. The Smith normal form is easy to compute using Mathematica.
We also call two matrices $A,B$ congruent if there exists
$X \\in \\operatorname{PSL}(n,\\mathbb{Z})$ such that $X^TAX=B$.
Now we have the following: if two matrices are congruent, then they have the same $D$.
But now, given two 4 by 4 matrices with same Smith normal form $D$,
how to verify they are congruent?
An if they are, how to find a matrix $X$ such that $X^T A X = B$.
To be more specific, suppose
$A = \\begin{bmatrix}
2 & -1 & -1 & -1 \\\\
-1 & 2 & 0 & 0 \\\\
-1 & 0 & 2 & 0 \\\\
-1 & 0 & 0 & 2 \\\\
\\end{bmatrix}$
and
$B = \\begin{bmatrix}
4 & -6 & 4 & -2 \\\\
-6 & 12 & -8 & 4 \\\\
4 & -8 & 6 & -3 \\\\
-2 & 4 & -3 & 2 \\\\
\\end{bmatrix}.$
I want to ask whether $A,B$ are congruent. Here is how far I got.
$A$, $B$ both have the same Smith normal form
$D = \\begin{bmatrix}
1 & 0 & 0 & 0 \\\\
0 & 1 & 0 & 0 \\\\
0 & 0 & 2 & 0 \\\\
0 & 0 & 0 & 2 \\\\
\\end{bmatrix}.$
So they define the same integer lattices.
But I do not know whether they are congruent.
I suspect they are congruent but I have no idea how to prove it.
Any ideas or comments are really appreciated.
By the way, $A$ is the Cartan matrix of $SO(8).$
I think it will not help.
I used Sage and typed them in as quadratic forms.
But I found that the `is_rationally_isometric` function only works
for number field but not integers ring (if I use integers,
there will be an error like no real_embedding).
The `is_rationally_isometric` is True.
But I do not know whether they are isometric over the integers.
If the answer is true, can I find such X?
sage: A = QuadraticForm(QQ, 4, [4, -12, 8, -4, 12, -16, 8, 6, -6, 2])
sage: print(A)
sage: A1 = QuadraticForm(QQ, 4, [2, -2, -2, -2, 2, 0, 0, 2, 0, 2])
sage: print(A1)
sage: A1.is_rationally_isometric(A)
TrueGracecatSat, 16 Jan 2021 03:33:07 +0100https://ask.sagemath.org/question/55294/Unimodular transformation matrix of LLL algorithmhttps://ask.sagemath.org/question/53618/unimodular-transformation-matrix-of-lll-algorithm/I also asked this question [on sage-support](https://groups.google.com/d/topic/sage-support/WDCtMtBN98Q/discussion).
I have a matrix `M1` with integer entries with 90 rows and 6 columns. After applying the LLL algorithm to M1, I get `M2 = M1.LLL()`. I want to get the corresponding unimodular transformation matrix `T` such that `T * M1 = M2`.
We can find `T` by `T = M2 * M1.pseudoinverse()` or `T = M1.solve_left(M2)`, but determinant of `T` becomes `0` i.e., `T.det()` equals `0`. I want `T.det()` to equal `1`.SantanuSun, 27 Sep 2020 12:00:58 +0200https://ask.sagemath.org/question/53618/Finding coprime integers near a lattice pointhttps://ask.sagemath.org/question/44435/finding-coprime-integers-near-a-lattice-point/ I have a list $L$ of ordered pairs $(n,m)$ where $n$ and $m$ are integers. I would like to know which elements $(n,m)$ in $L$ satisfy the property that $\gcd(n+i,m+j) \neq 1$ for $i =-1,0,1$ and $j =-1,0,1.$ For example the point $(55,21)$ has this property since $[(55+i,21+j) ] = [(54,20),(54,21),(54,22),(55,20),(55,21),(55,22),(56,20),(56,21),(56,22)].$ I have tried the following :
`for (n,m) in L:
for i in range(-1,2):
for j in range(-1,2):
if gcd(n+i,m+j)!=1:
print(n,m)`
which returns any point with $gcd =1$ which is not what I want.
Thanks very much for your help!
cihanMon, 26 Nov 2018 03:58:03 +0100https://ask.sagemath.org/question/44435/Action of lattice automorphism group on discriminant grouphttps://ask.sagemath.org/question/40645/action-of-lattice-automorphism-group-on-discriminant-group/I have a lattice $L$ with automorphism group $G=Aut(L)$. The action of $G$ on $L$ should induce an action on the discriminant group $D={\tilde L}/L$ such that we have a group homomorphism $\phi: Aut(L) \rightarrow Aut(D)$. The kernel of this map will be a normal subgroup $N$ of $G$. I need to be able to compute the action of the quotient $G/N$ on $D$. In the actual example I am interested in $L$ has rank $20$ and is defined through its Gram Matrix. $L$ is an even lattice. A simpler model of this situation would be to take $L$ to be a root lattice, say the $A_2$ root lattice to be concrete, $Aut(L)$ is the dihedral group $D_6$ arising as the product of the $Z_2$ outer automorphism and the $S_3$ Weyl group of $A_2$. The dual lattice $\tilde L$ is the weight lattice of $A_2$ and the discriminant group ${\tilde L}/L$ is $Z_3$ with one non-trivial automorphism, taking $g \rightarrow g^{-1}$. In this simple case everything is computable by hand, but for the case I am interested in I only have $Aut(L)$ presented in terms of $20 \times 20$ matrix generators and computing by hand seems too difficult. Can anyone provide any hints on how to get sage to do this? I can compute $Aut(L)$ and $Aut(D)$ using sage, my problem is in figuring out how to determine $N$ and the action of the quotient $G/N$ on $D$.jahTue, 16 Jan 2018 21:37:35 +0100https://ask.sagemath.org/question/40645/Enumerating lattice points in rational polytopeshttps://ask.sagemath.org/question/39135/enumerating-lattice-points-in-rational-polytopes/ Is there a way to ask Sage to count the number of lattice points in a rational polytope, say a polytope with vertices (0,0,0,0), (0,0,0,7), (0,0,7/2,7/2), (0,7/3,7/3,7/3),(7/4,7/4,7/4,7/4)?ProfHeimerThu, 12 Oct 2017 05:04:05 +0200https://ask.sagemath.org/question/39135/Decomposing a Root vector into simple rootshttps://ask.sagemath.org/question/32630/decomposing-a-root-vector-into-simple-roots/
Is there a sage functions which does the following:
Input = Root System / Ambient Lattice or Ambient space of irreducible (or even classical) Root System and a Root vector $v$
Output = a list containing the integers which expresses $v$ as a linear combination of simple roots.
Thank you for your help.
DBSMon, 22 Feb 2016 18:22:02 +0100https://ask.sagemath.org/question/32630/The lattice of number fieldshttps://ask.sagemath.org/question/28722/the-lattice-of-number-fields/Let $L$ be some number field, and $\sigma_1,...,\sigma_{(r+s)}$ its embeddings in the real\complex field. Given an element $a$ in a $L$, how can I produce the vector $(\sigma_1(a),...,\sigma_{(r+s)}(a))$ , or better yet, is there a function returning the lattice embedding of $\mathcal{O}_L$ inside $\mathbb{R}^r \times \mathbb{C}^s $? Similarly, after computing the units group is there some function that returns $(\log |\sigma_i(u) |)$ for a given unit $u$ or the corresponding unit lattice? OfirThu, 30 Jul 2015 07:38:53 +0200https://ask.sagemath.org/question/28722/Get decomposition of vector in basishttps://ask.sagemath.org/question/26904/get-decomposition-of-vector-in-basis/Hey!
I have a matrix that represents my basis (it's actually a lattice so the vectors are rows, but it's not important I can transpose)
I have a vector *aa* in a canonical basis, I want to know what's the linear combination in *R* of my lattice's vectors that gives my vector *aa* mimooWed, 20 May 2015 22:11:32 +0200https://ask.sagemath.org/question/26904/