---
title: "Creation of Vector Spaces and Arithmetic with Vectors"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/creation-arithmetic.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/creation-arithmetic.md"
part: "Matrices and Linear Algebra"
chapter: "Vector Spaces"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Matrices and Linear Algebra", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/index-matrices-linear-algebra.md"}
  - {"title": "Vector Spaces", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/index-vector-spaces.md"}
prev: {"title": "Introduction", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/introduction.md"}
next: {"title": "Subspaces, Quotient Spaces, and Homomorphisms", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/subspace-quotient-homomorphism.md"}
intrinsics:
  - {"name": "VectorSpace", "signature": "VectorSpace(K, n): Fld, RngIntElt -> ModTupFld"}
  - {"name": "KSpace", "signature": "KSpace(K, n): Fld, RngIntElt -> ModTupFld"}
  - {"name": "KModule", "signature": "KModule(K, n): Fld, RngIntElt -> ModFld"}
  - {"name": "KMatrixSpace", "signature": "KMatrixSpace(K, m, n): Fld, RngIntElt, RngIntElt -> ModMatFld"}
  - {"name": "Hom", "signature": "Hom(V, W): ModTupFld, ModTupFld -> ModMatFld"}
  - {"name": "VectorSpace", "signature": "VectorSpace(K, n, F): Fld, RngIntElt, Mtrx -> ModTupFld"}
  - {"name": "KSpace", "signature": "KSpace(K, n, F): Fld, RngIntElt, Mtrx -> ModTupFld"}
  - {"name": "elt", "signature": "elt<V | L>: ModTupFld, List -> ModTupFldElt"}
  - {"name": "!", "signature": "V ! Q: ModTupFld, [RngElt] -> ModTupFldElt"}
  - {"name": "CharacteristicVector", "signature": "CharacteristicVector(V, S): ModTupFld, { RngElt } -> ModTupFldElt"}
  - {"name": "!", "signature": "V ! 0: ModTupFld, RngIntElt -> ModTupFldElt"}
  - {"name": "Zero", "signature": "Zero(V): ModTupFld -> ModTupFldElt"}
  - {"name": "Random", "signature": "Random(V): ModTupFld -> ModTupFldElt"}
  - {"name": "ElementToSequence", "signature": "ElementToSequence(u): ModTupFldElt -> [RngElt]"}
  - {"name": "Eltseq", "signature": "Eltseq(u): ModTupFldElt -> [RngElt]"}
  - {"name": "+", "signature": "u + v: ModTupFldElt, ModTupFldElt -> ModTupFldElt"}
  - {"name": "-", "signature": "- u: ModTupFldElt -> ModTupFldElt"}
  - {"name": "-", "signature": "u - v: ModTupFldElt, ModTupFldElt -> ModTupFldElt"}
  - {"name": "*", "signature": "x * u: FldElt, ModTupFldElt -> ModTupFldElt"}
  - {"name": "*", "signature": "u * x: ModTupFldElt, FldElt -> ModTupFldElt"}
  - {"name": "/", "signature": "u / x: ModTupFldElt, FldElt -> ModTupFldElt"}
  - {"name": "NumberOfColumns", "signature": "NumberOfColumns(u): ModTupFldElt -> RngIntElt"}
  - {"name": "Ncols", "signature": "Ncols(u): ModTupFldElt -> RngIntElt"}
  - {"name": "Depth", "signature": "Depth(u): ModTupRngElt -> RngIntElt"}
  - {"name": "(u, v)", "signature": "(u, v): ModTupFldElt, ModTupFldElt -> FldElt"}
  - {"name": "InnerProduct", "signature": "InnerProduct(u, v): ModTupFldElt, ModTupFldElt -> FldElt"}
  - {"name": "IsZero", "signature": "IsZero(u): ModElt -> BoolElt"}
  - {"name": "Norm", "signature": "Norm(u): ModTupFldElt -> FldElt"}
  - {"name": "Normalise", "signature": "Normalise(u): ModTupFldElt -> ModTupFldElt"}
  - {"name": "Normalize", "signature": "Normalize(u): ModTupFldElt -> ModTupFldElt"}
  - {"name": "Rotate", "signature": "Rotate(u, k): ModTupFldElt, RngIntElt -> ModTupFldElt"}
  - {"name": "Rotate", "signature": "Rotate(~u, k): ModTupFldElt, RngIntElt"}
  - {"name": "NumberOfRows", "signature": "NumberOfRows(u): ModTupFldElt -> RngIntElt"}
  - {"name": "Nrows", "signature": "Nrows(u): ModTupFldElt -> RngIntElt"}
  - {"name": "Support", "signature": "Support(u): ModTupFldElt -> { RngElt }"}
  - {"name": "TensorProduct", "signature": "TensorProduct(u, v): ModTupFldElt, ModTupFldElt -> FldElt"}
  - {"name": "Trace", "signature": "Trace(u, F): ModTupFldElt, Fld -> ModTupFldElt"}
  - {"name": "Trace", "signature": "Trace(u): ModTupFldElt -> ModTupFldElt"}
  - {"name": "Weight", "signature": "Weight(u): ModTupFldElt -> RngIntElt"}
  - {"name": "u[i]", "signature": "u[i]: ModTupFldElt, RngIntElt -> RngElt"}
  - {"name": "u", "signature": "u[i]: ModTupFldElt, RngIntElt -> ModTupFldElt"}
  - {"name": "u", "signature": "u[i, j]: ModTupFldElt, RngIntElt, RngIntElt -> ModTupFldElt"}
  - {"name": "u[i] := x", "signature": "u[i] := x: ModTupFldElt, RngIntElt, RngElt -> ModTupFldElt"}
  - {"name": "u[i] := x", "signature": "u[i] := x: ModTupFldElt, RngIntElt, ModTupFldElt -> ModTupFldElt"}
  - {"name": "u[i, j] := x", "signature": "u[i, j] := x: ModTupFldElt, RngIntElt, RngIntElt, ModTupFldElt -> ModTupFldElt"}
examples:
  - "ex-d5b27e"
  - "ex-4fca7f"
  - "ex-df9b72"
  - "ex-d17116"
  - "ex-ca5d9a"
  - "ex-e5eb13"
  - "ex-876f3e"
---

# Creation of Vector Spaces and Arithmetic with Vectors

## Construction of a Vector Space

<a id="function-vectorspace-fld-rngintelt"></a>
### `VectorSpace(K, n): Fld, RngIntElt -> ModTupFld`

<a id="function-kspace-fld-rngintelt"></a>
### `KSpace(K, n): Fld, RngIntElt -> ModTupFld`

Given a field $K$ and a non-negative integer $n$, create the $n$-dimensional vector space $V = K^{(n)}$, consisting of all $n$-tuples over $K$. The vector space is created with respect to the standard basis, $e_1, \ldots, e_n$, where $e_i$ $(i = 1, \ldots, n)$ is the vector containing a $1$ in the $i$-th position and zeros elsewhere.

Use of the functions `VectorSpace` and `KSpace` ensures that subspaces of $V$ will be presented in embedded form.

<a id="function-kmodule-fld-rngintelt"></a>
### `KModule(K, n): Fld, RngIntElt -> ModFld`

Given a field $K$ and a non-negative integer $n$, create the $n$-dimensional vector space $V = K^{(n)}$, consisting of all $n$-tuples over $K$. The vector space is created with respect to the standard basis, $e_1, \ldots, e_n$, where $e_i$ $(i = 1, \ldots, n)$ is the vector containing a $1$ in the $i$-th position and zeros elsewhere.

Use of the function `KModule` ensures that subspaces of $V$ will be presented in reduced form. In all other respects, a vector space created by this function is identical to one created by `KSpace`.

<a id="function-kmatrixspace-fld-rngintelt-rngintelt"></a>
### `KMatrixSpace(K, m, n): Fld, RngIntElt, RngIntElt -> ModMatFld`

Given a field $K$ and integers $m$ and $n$ greater than one, create the vector space $K^{(m \times n)}$, consisting of all $m \times n$ matrices over $K$. The vector space is created with the standard basis, $\{E_{ij}\  |\  i = 1 \ldots, m, j = 1 \ldots, n\}$, where $E_{ij}$ is the matrix having a $1$ in the ($i, j$)-th position and zeros elsewhere. Note that for a matrix space, subspaces will always be presented in embedded form, i.e. there is no reduced mode available for matrix spaces.

<a id="function-hom-modtupfld-modtupfld"></a>
### `Hom(V, W): ModTupFld, ModTupFld -> ModMatFld`

If $V$ is the vector space $K^{(m)}$ and $W$ is the vector space $K^{(n)}$, create the matrix space ${\operatorname{Hom}}_{K}(V, W)$ as the vector space $K^{(m \times n)}$, represented as the set of all $m \times n$ matrices over $K$. The vector space is created with the standard basis, $\{E_{ij}\  |\  i = 1 \ldots, m, j = 1 \ldots, n\}$, where $E_{ij}$ is the matrix having a $1$ in the ($i, j$)-th position and zeros elsewhere.

<a id="example-ex-d5b27e"></a>
### `Example: Rational Vector Space of Dimension 6 (ex-d5b27e)`

We construct the vector space $V$ consisting of $6$-tuples over the rational field.

```magma
> Q := RationalField();
> V := VectorSpace(Q, 6);
> V;
Vector space of dimension 6 over Rational Field
```

<a id="example-ex-4fca7f"></a>
### `Example: Matrix Space over a Quadratic Field (ex-4fca7f)`

We construct the matrix space $M$ consisting of $3 \times 5$ matrices over the field ${\mathbb{Q}}(\sqrt{5})$.

```magma
> K<w> := QuadraticField(5);
> V := KMatrixSpace(K, 3, 5);
> V;
Full Vector Space of 3 by 5 matrices over Quadratic Field Q(w)
```

## Construction of a Vector Space with Inner Product Matrix

<a id="function-vectorspace-fld-rngintelt-mtrx"></a>
### `VectorSpace(K, n, F): Fld, RngIntElt, Mtrx -> ModTupFld`

<a id="function-kspace-fld-rngintelt-mtrx"></a>
### `KSpace(K, n, F): Fld, RngIntElt, Mtrx -> ModTupFld`

Given a field $K$, a non-negative integer $n$, and a square $n \times n$ symmetric matrix $F$, create the $n$-dimensional vector space $V = K^{(n)}$ (in embedded form), with inner product matrix $F$. This is the same as `VectorSpace(K, n)`, except that the functions `Norm` and `InnerProduct` (see below) will be with respect to the inner product matrix $F$.

## Construction of a Vector

<a id="constructor-constructor-elt-modtupfld-list-modtupfldelt"></a>
### `elt<V | L>: ModTupFld, List -> ModTupFldElt`

**(1)**
Suppose $V$ is a subspace of the vector space $K^{(n)}$. Given elements $a_1, \ldots, a_n$ belonging to $K$, construct the vector $v = (a_1, \ldots, a_n)$ as a vector of $V$. Note that if $v$ is not an element of $V$, an error will result.

**(2)**
Suppose $V$ is a subspace of the matrix space $K^{(m \times n)}$. Given elements $a_1, \ldots, a_{mn}$ belonging to $K$, construct the matrix $m = (a_1, \ldots, a_{mn})$ as an element of $V$. Note that if $m$ is not an element of $V$, an error will result.

<a id="operation-op-modtupfld-rngelt"></a>
### `V ! Q: ModTupFld, [RngElt] -> ModTupFldElt`

**(1)**
Suppose $V$ is a subspace of the vector space $K^{(n)}$. Given elements $a_1, \ldots, a_n$ belonging to $K$, construct the vector $v = (a_1, \ldots, a_n)$ as a vector of $V$. Note that if $v$ is not an element of $V$, an error will result.

**(2)**
Suppose $V$ is a subspace of the matrix space $K^{(m \times n)}$. Given elements $a_1, \ldots, a_{mn}$ belonging to $K$, construct the matrix $m = (a_1, \ldots, a_{mn})$ as an element of $V$. Note that if $m$ is not an element of $V$, an error will result.

<a id="function-characteristicvector-modtupfld-rngelt"></a>
### `CharacteristicVector(V, S): ModTupFld, { RngElt } -> ModTupFldElt`

Given a subspace $V$ of the vector space $K^{(n)}$ together with a set $S$ of integers lying in the interval $[1, n]$, return the characteristic number of $S$ as a vector of $V$.

<a id="operation-op-modtupfld-rngintelt"></a>
### `V ! 0: ModTupFld, RngIntElt -> ModTupFldElt`

<a id="function-zero-modtupfld"></a>
### `Zero(V): ModTupFld -> ModTupFldElt`

The zero element for the vector space $V$.

<a id="function-random-modtupfld"></a>
### `Random(V): ModTupFld -> ModTupFldElt`

Given a vector space $V$ defined over a finite field, return a random vector.

<a id="example-ex-df9b72"></a>
### `Example: Vector over a Finite Field (ex-df9b72)`

We create the 5-dimensional vector space $V$ over ${\bf F}_{4}$ and define the vector $u = (1, w, 1+w, 0, 0)$, where $w$ is a primitive element of ${\bf F}_{4}$.

```magma
> K<w> := GaloisField(4);
> V    := VectorSpace(K, 5);
> u    := V ! [1, w, 1+w, 0, 0];
> u;
(1 w w + 1 0 0)
> zero := V ! 0;
> zero;
(0 0 0 0 0)
r := Random(V);
(1 0 w 1 w + 1)
```

<a id="example-ex-d17116"></a>
### `Example: Matrix over a Number Field (ex-d17116)`

We create an element belonging to the space of $3 \times 4$ matrices over the number field ${\mathbb{Q}}(w)$, where $w$ is a root of $x^7 - 7x + 3$.

```magma
> R<x> := PolynomialRing(RationalField());
> L<w> := NumberField(x^7 - 7*x + 3);
> L34 := KMatrixSpace(L, 3, 4);
> a := L34 ! [ 1, w, 0, -w, 0, 1+w, 2, -w^3, w-w^3, 2*w, 1/3, 1 ];
> a;
[1    w    0    -1 * w]
[0    w + 1    2    -1 * w^3]
[-1 * w^3 + w    2 * w    1/3    1]
```

## Deconstruction of a Vector

<a id="function-elementtosequence-modtupfldelt"></a>
### `ElementToSequence(u): ModTupFldElt -> [RngElt]`

<a id="function-eltseq-modtupfldelt"></a>
### `Eltseq(u): ModTupFldElt -> [RngElt]`

Given an element $u$ belonging to the $K$-vector space $V$, return $u$ in the form of a sequence $Q$ of elements of $V$. Thus, if $u$ is an element of $K^{(n)}$, then $Q[i] = u[i]$, $1 \leq i \leq n$.

## Arithmetic with Vectors

For the following operations the vectors $u$ and $v$ must belong to the same vector space i.e. the same tuple space $K^{(n)}$ or the same matrix space $K^{(m \times n)}$. The scalar $a$ must belong to the field $K$.

<a id="operation-op-plus-modtupfldelt-modtupfldelt"></a>
### `u + v: ModTupFldElt, ModTupFldElt -> ModTupFldElt`

Sum of the vectors $u$ and $v$, where $u$ and $v$ lie in the same vector space.

<a id="operation-operation-modtupfldelt-modtupfldelt"></a>
### `- u: ModTupFldElt -> ModTupFldElt`

Additive inverse of the vector $u$.

<a id="operation-op-minus-modtupfldelt-modtupfldelt"></a>
### `u - v: ModTupFldElt, ModTupFldElt -> ModTupFldElt`

Difference of the vectors $u$ and $v$, where $u$ and $v$ lie in the same vector space.

<a id="operation-op-times-fldelt-modtupfldelt"></a>
### `x * u: FldElt, ModTupFldElt -> ModTupFldElt`

<a id="operation-op-times-modtupfldelt-fldelt"></a>
### `u * x: ModTupFldElt, FldElt -> ModTupFldElt`

The scalar product of the vector $u$ belonging to the $K$-vector space and the field element $x$ belonging to $K$.

<a id="operation-op-div-modtupfldelt-fldelt"></a>
### `u / x: ModTupFldElt, FldElt -> ModTupFldElt`

The scalar product of the vector $u$ belonging to the $K$-vector space and the field element $1/x$ belonging to $K$ where $x$ is non-zero.

<a id="function-numberofcolumns-modtupfldelt"></a>
### `NumberOfColumns(u): ModTupFldElt -> RngIntElt`

<a id="function-ncols-modtupfldelt"></a>
### `Ncols(u): ModTupFldElt -> RngIntElt`

The number of columns in the vector $u$.

<a id="function-depth-modtuprngelt"></a>
### `Depth(u): ModTupRngElt -> RngIntElt`

The index of the first non-zero entry of the vector $u$ (0 if none such).

<a id="literal-literal-u-v-modtupfldelt-modtupfldelt-fldelt"></a>
### `(u, v): ModTupFldElt, ModTupFldElt -> FldElt`

<a id="function-innerproduct-modtupfldelt-modtupfldelt"></a>
### `InnerProduct(u, v): ModTupFldElt, ModTupFldElt -> FldElt`

Return the inner product of the vectors $u$ and $v$ with respect to the inner product defined on the space. If an inner product matrix $F$ is given when the space is created, then this is defined to be $u\cdot F\cdot v^{tr}$. Otherwise, this is simply $u\cdot v^{tr}$.

<a id="function-iszero-modelt"></a>
### `IsZero(u): ModElt -> BoolElt`

Returns `true` iff the vector $u$ belonging to a vector space is the zero element.

<a id="function-norm-modtupfldelt"></a>
### `Norm(u): ModTupFldElt -> FldElt`

Return the norm product of the vector $u$ with respect to the inner product defined on the space. If an inner product matrix $F$ is given when the space is created, then this is defined to be $u\cdot F\cdot u^{tr}$. Otherwise, this is simply $u\cdot u^{tr}$.

<a id="function-normalise-modtupfldelt"></a>
### `Normalise(u): ModTupFldElt -> ModTupFldElt`

<a id="function-normalize-modtupfldelt"></a>
### `Normalize(u): ModTupFldElt -> ModTupFldElt`

Given an element $u$, not the zero element, belonging to the $K$-vector space $V$, return ${1\over a}*u$, where $a$ is the first non-zero component of $u$. If $u$ is the zero vector, it is returned. The net effect is that `Normalize(u)` always returns a vector $v$ in the subspace generated by $u$, such that the first non-zero component of $v$ (if existent) is $K!1$.

<a id="function-rotate-modtupfldelt-rngintelt"></a>
### `Rotate(u, k): ModTupFldElt, RngIntElt -> ModTupFldElt`

Given a vector $u$, return the vector obtained from $u$ by rotating by k coordinate positions.

<a id="procedure-rotate-modtupfldelt-rngintelt-ref"></a>
### `Rotate(~u, k): ModTupFldElt, RngIntElt`

Given a vector $u$, destructively rotate $u$ by k coordinate positions.

<a id="function-numberofrows-modtupfldelt"></a>
### `NumberOfRows(u): ModTupFldElt -> RngIntElt`

<a id="function-nrows-modtupfldelt"></a>
### `Nrows(u): ModTupFldElt -> RngIntElt`

The number of rows in the vector $u$ (1 of course; included for completeness).

<a id="function-support-modtupfldelt"></a>
### `Support(u): ModTupFldElt -> { RngElt }`

A set of integers giving the positions of the non-zero components of the vector $u$.

<a id="function-tensorproduct-modtupfldelt-modtupfldelt"></a>
### `TensorProduct(u, v): ModTupFldElt, ModTupFldElt -> FldElt`

The tensor (Kronecker) product of the vectors $u$ and $v$. The resulting vector has degree equal to the product of the degrees of $u$ and $v$.

<a id="function-trace-modtupfldelt-fld"></a>
### `Trace(u, F): ModTupFldElt, Fld -> ModTupFldElt`

<a id="function-trace-modtupfldelt"></a>
### `Trace(u): ModTupFldElt -> ModTupFldElt`

Given a vector belonging to the space $K^{(n)}$, and a subfield $F$ of $K$, return the vector obtained by replacing each component of $u$ by its trace over the subfield $F$. If $F$ is the prime field of $K$, it may be omitted.

<a id="function-weight-modtupfldelt"></a>
### `Weight(u): ModTupFldElt -> RngIntElt`

The number of non-zero components of the vector $u$.

<a id="example-ex-ca5d9a"></a>
### `Example: Vector Arithmetic over a Cyclotomic Field (ex-ca5d9a)`

We illustrate the use of the arithmetic operators for module elements by applying them to elements of the $4$-dimensional vector space over the field ${\mathbb{Q}}(w)$, where $w$ is an $8$-th root of unity.

```magma
> K<w> := CyclotomicField(8);
> V := VectorSpace(K, 4);
> x := V ! [ w, w^2, w^4, 0];
> y := V ! [1, w, w^2, w^4];
> x + y;
(  w + 1 w^2 + w w^2 - 1      -1)
> -x;
(  -w -w^2    1    0)
> x - y;
(   w - 1  w^2 - w -w^2 - 1        1)
> w * x;
(w^2 w^3  -w   0)
> y * w^ -4;
(  -1   -w -w^2    1)
> Normalize(x);
(  1   w w^3   0)
> InnerProduct(x, y);
w^2 + 2*w
> z := V ! [1, 0, w, 0 ];
> z;
(1 0 w 0)
> Support(z);
{ 1, 3 }
```

<a id="example-ex-e5eb13"></a>
### `Example: Defining a Nontrivial Inner Product (ex-e5eb13)`

We illustrate how one can define a non-trivial inner product on a space.

```magma
> Q := RationalField();
> F := SymmetricMatrix(Q, [1, 0,2, 0,0,3, 1,2,3,4]);
> F;
[1 0 0 1]
[0 2 0 2]
[0 0 3 3]
[1 2 3 4]
> V := VectorSpace(Q, 4, F);
> V;
Full Vector space of degree 4 over Rational Field
Inner Product Matrix:
[1 0 0 1]
[0 2 0 2]
[0 0 3 3]
[1 2 3 4]
> v := V![1,0,0,0];
> Norm(v);
1
> w := V![0,1,0,0];
> Norm(w);
2
> InnerProduct(v, w);
0
> z := V![0,0,0,1];
> Norm(z);
4
> InnerProduct(v, z);
1
> InnerProduct(w, z);
2
```

## Indexing Vectors and Matrices

The indexing operations have a different meaning depending upon whether they are applied to a tuple space or a matrix space.

<a id="literal-literal-u-i-modtupfldelt-rngintelt-rngelt"></a>
### `u[i]: ModTupFldElt, RngIntElt -> RngElt`

<a id="indexed-indexed-u-modtupfldelt-rngintelt-modtupfldelt"></a>
### `u[i]: ModTupFldElt, RngIntElt -> ModTupFldElt`

<a id="indexed-indexed-u-modtupfldelt-rngintelt-rngintelt-modtupfldelt"></a>
### `u[i, j]: ModTupFldElt, RngIntElt, RngIntElt -> ModTupFldElt`

Given a vector $u$ belonging to a $K$-vector space $V$, the result of this operation depends upon whether $V$ is a tuple or matrix space. If $V$ is a subspace of $K^{(n)}$, and $i$, $1 \leq i\leq n$, is a positive integer, the $i$-th component of the vector $u$ is returned (as an element of the field $K$). If $V$ is a subspace of $K^{(m \times n)}$, and $i$, $1 \leq i\leq m$, is a positive integer, $u[i]$ will return the $i$-th row of the matrix $u$ (as an element of the vector space $K^{(n)}$). Similarly, if $i$ and $j$, $1 \leq i\leq m$, $1 \leq j\leq n$, are positive integers, $u[i, j]$ will return the $(i,j)$-th component of the matrix $u$ (as an element of $K$).

<a id="literal-literal-u-i-x-modtupfldelt-rngintelt-rngelt-modtupfldelt"></a>
### `u[i] := x: ModTupFldElt, RngIntElt, RngElt -> ModTupFldElt`

<a id="literal-literal-u-i-x-modtupfldelt-rngintelt-modtupfldelt-modtupfldelt"></a>
### `u[i] := x: ModTupFldElt, RngIntElt, ModTupFldElt -> ModTupFldElt`

<a id="literal-literal-u-i-j-x-modtupfldelt-rngintelt-rngintelt-modtupfldelt-modtupfldelt"></a>
### `u[i, j] := x: ModTupFldElt, RngIntElt, RngIntElt, ModTupFldElt -> ModTupFldElt`

Given a vector $u$ belonging to a $K$-vector space $V$, and an element $x$ of $K$, the result of this operation depends upon whether $V$ is a tuple or matrix space. If $V$ is a subspace of $K^{(n)}$, and $i$, $1 \leq i\leq n$, is a positive integer, the $i$-th component of the vector $u$ is redefined to be $x$. If $V$ is a subspace of $K^{(m \times n)}$ and $1 \leq i\leq m$ is a positive integer and $x$ is an element of $K^{(n)}$, `u[i] := x` will redefine the $i$-th row of the matrix $u$ to be the vector $x$, where $x$ must be an element of $K^{(n)}$. Similarly, if $1 \leq i\leq m$, $1 \leq j\leq n$, are positive integers, `u[i, j] := x` will redefine the $(i,j)$-th component of the matrix $u$ to be $x$, where $x$ must be an element of $K$.

<a id="example-ex-876f3e"></a>
### `Example: Indexing Tuple and Matrix Spaces (ex-876f3e)`

We illustrate the use of the indexing operators for vector space elements by applying them to a $3$-dimensional tuple space and a $2 \times 3$ matrix space over the field ${\mathbb{Q}}(w)$, where $w$ is an $8$-th root of unity.

```magma
> K<w> := CyclotomicField(8);
> V := VectorSpace(K, 3);
> u := V ! [ 1 + w, w^ 2, w^ 4];
> u;
((1 + w)     (w^2)           -1)
> u[3];
-1
> u[3] := 1 + w - w^7;
> u;
((1 + w) (w^2) (1 + w + w^3))
> // We now demonstrate indexing a matrix space
> W := KMatrixSpace(K, 2, 3);
> l := W ! [ 1 - w, 1 + w, 1 + w + w^2, 0, 1 - w^7, 1 - w^3 + w^6 ];
> l;
[(1 - w) (1 + w) (1 + w + w^2)]
[0 (1 + w^3) (1 - w^2 - w^3)]
> l[2];
(0 (1 + w^3) (1 - w^2 - w^3))
> l[2,2];
(1 + w^3)
> m := l[2];
> m;
(0 (1 + w^3) (1 - w^2 - w^3))
> l[2] := u;
> l;
[(1 - w) (1 + w) (1 + w + w^2)]
[(1 + w) (w^2) -1]
> l[2, 3] := 1 + w - w^7;
> l;
[(1 - w) (1 + w) (1 + w + w^2)]
[(1 + w) (w^2) (1 + w + w^3)]
```
