# Lattice Elements

The following functions allow basic operations on elements of lattices. The elements of lattices are simply (row) vectors, just as for $R$-spaces. Most of the operations for $R$-space elements are also applicable to lattice elements.

## Creation of Lattice Elements

### `L . i: Lat, RngIntElt -> LatElt`

Return the $i$-th basis element of the current basis of the lattice $L$.

### `L ! Q: Lat, [ RngElt ] -> LatElt`

### `elt<L | Q>: Lat, [ RngElt ] -> LatElt`

Given a lattice $L$ of degree $n$ and a sequence $Q$ of length $n$, create the lattice element with the corresponding sequence elements as entries. The sequence must consist of elements coercible into the base ring of $L$. The resulting vector must lie within $L$.

### `CoordinatesToElement(L, C): Lat, [ RngIntElt ] -> LatElt`

### `Coordelt(L, C): Lat, [ RngIntElt ] -> LatElt`

### `CoordinatesToElement(L, C): Lat, Mtrx -> LatElt`

### `Coordelt(L, C): Lat, Mtrx -> LatElt`

Given a lattice $L$ of rank $m$ and a sequence or vector $C=[c_1, \ldots, c_m]$ of length $m$ of *integers*, create the lattice element $c_1 \cdot b_1 + \ldots + c_m \cdot b_m$, where $[b_1, \ldots, b_m]$ is the basis of $L$.

### `L ! 0: Lat, RngIntElt -> LatElt`

### `Zero(L): Lat -> LatElt`

Return the zero element of the lattice $L$.

## Operations on Lattice Elements

### `- v: LatElt -> LatElt`

Given an element $v$ in a lattice $L$, return its negation $-v$ in $L$.

### `v + w: LatElt, LatElt -> LatElt`

Given elements $v$ and $w$ in a lattice $L$, return the sum $v+w$ in $L$.

### `v - w: LatElt, LatElt -> LatElt`

Given elements $v$ and $w$ in a lattice $L$, return the difference $v-w$ in $L$.

### `v * s: LatElt, RngIntElt -> .`

### `s * v: RngIntElt, LatElt -> .`

Given an element $v$ in a lattice $L$ and a scalar $s$ of the ring $S$, return the product $s\cdot v$ (scalar multiplication of $v$ by $s$). If $s$ is an integer, the resulting vector will lie in $L$; otherwise the resulting vector will lie in the $R$-space of the appropriate degree whose coefficient ring is the parent $S$ of $s$.

### `v / s: LatElt, RngIntElt -> .`

Given an element $v$ in a lattice $L$ and a scalar $s$ of the ring $S$, return the product $(1/s)\cdot v$ (scalar multiplication of $v$ by $1/s$). The resulting vector will always lie in the $R$-space of the appropriate degree whose coefficient ring is the field of fractions of the parent $S$ of $s$.

### `v div d: LatElt, RngIntElt -> LatElt`

Given an element $v$ in a lattice $L$ and an *integer* $d$, return the vector $(1/d)\cdot v$ (scalar multiplication of $v$ by $1/d$) as an element of $L$ if the scaled vector lies in $L$. If the scaled vector does not lie in $L$, an error ensues. Note that this is different from $v/d$.

### `v +:= w: LatElt, LatElt`

(Assignment statement.) Replace lattice element $v$ by the sum $v+w$.

### `v -:= w: LatElt, LatElt`

(Assignment statement.) Replace lattice element $v$ by the difference $v-w$.

### `v *:= n: LatElt, RngIntElt`

(Assignment statement.) Replace lattice element $v$ by the scalar product $n\cdot v$, where $n$ is an integer.

### `v * T: LatElt, AlgMatElt -> LatElt`

### `v * T: LatElt, ModMatRngElt -> LatElt`

### `v * T: LatElt, GrpMatElt -> LatElt`

Given an element $v$ in a lattice $L$ of degree $n$, return the result of multiplying $v$ from the right by the $n\times n$ matrix $T$. The matrix $T$ may be any matrix which is $n$ by $n$ and over the base ring of $L$. The resulting product must lie in the lattice $L$.

### `InnerProduct(v, w): LatElt, LatElt -> RngElt`

### `(v, w)`

Given elements $v$ and $w$ of a lattice $L$, return their inner product $(v, w)$ with respect to the inner product of $L$. This is $v M w^{tr}$ where $M$ is the inner product matrix of $L$.

### `Norm(v): LatElt -> RngElt`

Given an element $v$ of a lattice $L$, return its norm $(v, v)$ with respect to the inner product of $L$. This is $v M v^{tr}$ where $M$ is the inner product matrix of $L$. Note that in the case of a lattice with standard Euclidean inner product this is the square of the usual Euclidean length.

### `Length(v, K): LatElt, Fld -> FldReElt`

### `Length(v): LatElt -> FldReElt`

Given an element $v$ of a lattice $L$, return its length $\sqrt{(v,v)}$ with respect to the inner product of $L$ as an element of the real field $K$. This is $\sqrt{v M v^{tr}}$ where $M$ is the inner product matrix of $L$. The argument for the real field $K$ may be omitted, in which case $K$ is taken to be the current default real field. In the case of a lattice with standard Euclidean inner product this is the usual Euclidean length.

### `Support(v): LatElt -> SetEnum`

Given an element $v$ of a lattice $L$, return its support, i.e., the numbers of the columns at which $v$ has non-zero entries.

## Predicates and Boolean Operations

### `v in L: LatElt, Lat -> BoolElt`

Given an element $v$ of a lattice which is compatible with the lattice $L$, return `true` if and only if $v$ is in $L$.

### `v eq w: LatElt, LatElt -> BoolElt`

Given elements $v$ and $w$ of a lattice $L$, return `true` if and only if lattice elements $v$ and $w$ of lattice $L$ are equal.

### `v ne w: LatElt, LatElt -> BoolElt`

Given elements $v$ and $w$ of a lattice $L$, return `false` if and only if lattice elements $v$ and $w$ of lattice $L$ are equal.

### `IsZero(v): LatElt -> BoolElt`

Given an element $v$ of a lattice $L$, return `true` if and only if $v$ is the zero element $L$.

## Access Operations

### `ElementToSequence(v): LatElt -> [ RngElt ]`

### `Eltseq(v): LatElt -> [ RngElt ]`

Given an element $v$ of a lattice $L$ of degree $n$, return the sequence of entries of $v$ of length $n$.

### `Coordinates(v): LatElt -> [ RngIntElt ]`

Given an element $v$ of a lattice $L$ having ${\mathbb{Z}}$-basis $[b_1, \ldots, b_m]$, return a sequence [$c_1, \ldots, c_m$] of elements of ${\mathbb{Z}}$ giving the (unique) coordinates of $v$ relative to the ${\mathbb{Z}}$-basis, so that $v = c_1 \cdot b_1 + \ldots + c_m \cdot b_m$.

### `Coordinates(L, v): Lat, LatElt -> [ RngIntElt ]`

Given a lattice $L$ of degree $n$ having ${\mathbb{Z}}$-basis $[b_1, \ldots, b_m]$, together with an element $v$ of a lattice $L'$ (also of degree $n$), return a sequence [$c_1, \ldots, c_m$] of elements of ${\mathbb{Z}}$ giving the (unique) coordinates of $v$ relative to the ${\mathbb{Z}}$-basis of $L$, so that $v = c_1 \cdot b_1 + \ldots + c_m \cdot b_m$.

### `CoordinateVector(v): LatElt -> LatElt`

Given an element $v$ of a lattice $L$ having ${\mathbb{Z}}$-basis $[b_1, \ldots, b_m]$, return the vector $c = (c_1, \ldots, c_m)$ of the coordinate lattice $C$ of $L$ (see the function `CoordinateLattice`) giving the (unique) coordinates of $v$ relative to the ${\mathbb{Z}}$-basis, so that $v = c_1 \cdot b_1 + \ldots + c_m \cdot b_m$.

### `CoordinateVector(L, v): Lat, LatElt -> LatElt`

Given a lattice $L$ of degree $n$ having ${\mathbb{Z}}$-basis $[b_1, \ldots, b_m]$, together with an element $v$ of a lattice $L'$ (also of degree $n$), return the vector $c = (c_1, \ldots, c_m)$ of the coordinate lattice $C$ of $L$ (see the function `CoordinateLattice`) giving the (unique) coordinates of $v$ relative to the ${\mathbb{Z}}$-basis of $L$, so that $v = c_1 \cdot b_1 + \ldots + c_m \cdot b_m$.

### `Example: Lattice Functions (ex-0121de)`

This example demonstrates simple uses of the operations on lattice elements.

```magma
> L := LatticeWithBasis(3, [1,0,0, 1,2,3, 3,6,2]);
> L;
Lattice of rank 3 and degree 3
Basis:
(1 0 0)
(1 2 3)
(3 6 2)
> Coordelt(L, [1, 2, 1]);
( 6 10  8)
> v := L.2;
> w := L ! [2, 4, 6];
> Eltseq(v);
[ 1, 2, 3 ]
> Coordinates(w);
[ 0, 2, 0 ]
> Coordelt(L, [1, 1, 1]);
(5 8 5)
> Norm(v);
14
> InnerProduct(v, w);
28
> A := MatrixRing(Integers(), 3);
> X := A ! [0,-1,0, 1,0,0, 0,1,2];
> X;
[ 0 -1  0]
[ 1  0  0]
[ 0  1  2]
> u := L.1 + L.3;
> Determinant(X);
2
> Norm(u);
56
> u * X;
( 6 -2  4)
> Norm(u * X);
56

```
