---
title: "Bases"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/basis.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/basis.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": "Reducing Vectors Relative to a Subspace", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/reducing-vectors.md"}
next: {"title": "Operations with Linear Transformations", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/VectorSpaces/linear-transformation.md"}
intrinsics:
  - {"name": "VectorSpaceWithBasis", "signature": "VectorSpaceWithBasis(Q): [ModTupFldElt] -> ModTupFld"}
  - {"name": "VectorSpaceWithBasis", "signature": "VectorSpaceWithBasis(a): AlgMatElt -> ModTupFld"}
  - {"name": "VectorSpaceWithBasis", "signature": "VectorSpaceWithBasis(a): ModMatFldElt -> ModTupFld"}
  - {"name": "KSpaceWithBasis", "signature": "KSpaceWithBasis(Q): [ModTupFldElt] -> ModTupFld"}
  - {"name": "KSpaceWithBasis", "signature": "KSpaceWithBasis(a): AlgMatElt -> ModTupFld"}
  - {"name": "KSpaceWithBasis", "signature": "KSpaceWithBasis(a): ModMatFldElt -> ModTupFld"}
  - {"name": "KModuleWithBasis", "signature": "KModuleWithBasis(Q): [ModTupFldElt] -> ModTupFld"}
  - {"name": "Basis", "signature": "Basis(V): ModTupFld -> [ModTupFldElt]"}
  - {"name": "BasisElement", "signature": "BasisElement(V, i): ModTupFld, RngIntElt -> ModTupFldElt"}
  - {"name": "BasisMatrix", "signature": "BasisMatrix(V): ModTupFld -> ModMatElt"}
  - {"name": "Coordinates", "signature": "Coordinates(V, v): ModTupFld, ModTupFldElt -> [FldElt]"}
  - {"name": "Dimension", "signature": "Dimension(V): ModTupFld -> RngIntElt"}
  - {"name": "ExtendBasis", "signature": "ExtendBasis(Q, U): [ModTupFldElt], ModTupFld -> [ModTupFldElt]"}
  - {"name": "ExtendBasis", "signature": "ExtendBasis(U, V): ModTupFld, ModTupFld -> [ModTupFldElt]"}
  - {"name": "IsIndependent", "signature": "IsIndependent(S): { ModTupFldElt} -> BoolElt"}
  - {"name": "IsIndependent", "signature": "IsIndependent(Q): [ ModTupFldElt ] -> BoolElt"}
examples:
  - "ex-a4fb0c"
---

# Bases

This section is concerned with the construction of bases for vector spaces.

<a id="function-vectorspacewithbasis-modtupfldelt"></a>
## `VectorSpaceWithBasis(Q): [ModTupFldElt] -> ModTupFld`

<a id="function-vectorspacewithbasis-algmatelt"></a>
## `VectorSpaceWithBasis(a): AlgMatElt -> ModTupFld`

<a id="function-vectorspacewithbasis-modmatfldelt"></a>
## `VectorSpaceWithBasis(a): ModMatFldElt -> ModTupFld`

<a id="function-kspacewithbasis-modtupfldelt"></a>
## `KSpaceWithBasis(Q): [ModTupFldElt] -> ModTupFld`

<a id="function-kspacewithbasis-algmatelt"></a>
## `KSpaceWithBasis(a): AlgMatElt -> ModTupFld`

<a id="function-kspacewithbasis-modmatfldelt"></a>
## `KSpaceWithBasis(a): ModMatFldElt -> ModTupFld`

<a id="function-kmodulewithbasis-modtupfldelt"></a>
## `KModuleWithBasis(Q): [ModTupFldElt] -> ModTupFld`

Create a vector space having as basis the terms of $B$ (rows of $a$).

<a id="function-basis-modtupfld"></a>
## `Basis(V): ModTupFld -> [ModTupFldElt]`

The current basis for the vector space $V$, returned as a sequence of vectors.

<a id="function-basiselement-modtupfld-rngintelt"></a>
## `BasisElement(V, i): ModTupFld, RngIntElt -> ModTupFldElt`

The $i$-th basis element for the vector space $V$.

<a id="function-basismatrix-modtupfld"></a>
## `BasisMatrix(V): ModTupFld -> ModMatElt`

The current basis for the vector space $V$, returned as the rows of a matrix belonging to the matrix space $K^{(m \times n)}$, where $m$ is the dimension of $V$ and $n$ is the over-dimension of $V$.

<a id="function-coordinates-modtupfld-modtupfldelt"></a>
## `Coordinates(V, v): ModTupFld, ModTupFldElt -> [FldElt]`

Given a vector $v$ belonging to the $r$-dimensional $K$-vector space $V$, with basis $v_1, \ldots, v_r$, return a sequence $[a_1, \ldots, a_r]$ of elements of $K$ giving the coordinates of $v$ relative to the $V$-basis: $v = a_1*v_1 + \cdots +a_r*v_r$.

<a id="function-dimension-modtupfld-2"></a>
## `Dimension(V): ModTupFld -> RngIntElt`

The dimension of the vector space $V$.

<a id="function-extendbasis-modtupfldelt-modtupfld"></a>
## `ExtendBasis(Q, U): [ModTupFldElt], ModTupFld -> [ModTupFldElt]`

Given a sequence $Q$ containing $r$ linearly independent vectors belonging to the vector space $U$, extend the vectors of $Q$ to a basis for $U$. The basis is returned in the form of a sequence $T$ such that $T[i] = Q[i], i = 1, \ldots r$.

<a id="function-extendbasis-modtupfld-modtupfld"></a>
## `ExtendBasis(U, V): ModTupFld, ModTupFld -> [ModTupFldElt]`

Given an $r$-dimensional subspace $U$ of the vector space $V$, return a basis for $V$ in the form of a sequence $T$ of elements such that the first $r$ elements correspond to the given basis vectors for $U$.

<a id="function-isindependent-modtupfldelt"></a>
## `IsIndependent(S): { ModTupFldElt} -> BoolElt`

Given a set $S$ of elements belonging to the vector space $V$, return `true` if the elements of $S$ are linearly independent.

<a id="function-isindependent-modtupfldelt-2"></a>
## `IsIndependent(Q): [ ModTupFldElt ] -> BoolElt`

Given a sequence $Q$ of elements belonging to the vector space $V$, return `true` if the terms of $Q$ are linearly independent.

<a id="example-ex-a4fb0c"></a>
## `Example: Bases of the Ternary Golay Code (ex-a4fb0c)`

These operations will be illustrated in the context of the subspace $G3$ of the $11$-dimensional vector space over ${\bf F}_{3}$ defining the ternary Golay code.

```magma
> V11 := VectorSpace(FiniteField(3), 11);
> G3  := sub< V11 |  [1,0,0,0,0,0,1,1,1,1,1], [0,1,0,0,0,0,0,1,2,2,1],
>                    [0,0,1,0,0,0,1,0,1,2,2], [0,0,0,1,0,0,2,1,0,1,2],
>                    [0,0,0,0,1,0,2,2,1,0,1], [0,0,0,0,0,1,1,2,2,1,0] >;
> Dimension(G3);
    6
> Basis(G3);
[
    (1 0 0 0 0 0 1 1 1 1 1),
    (0 1 0 0 0 0 0 1 2 2 1),
    (0 0 1 0 0 0 1 0 1 2 2),
    (0 0 0 1 0 0 2 1 0 1 2),
    (0 0 0 0 1 0 2 2 1 0 1),
    (0 0 0 0 0 1 1 2 2 1 0)
]
> S := ExtendBasis(G3, V11);
> S;
[
    (1 0 0 0 0 0 1 1 1 1 1),
    (0 1 0 0 0 0 0 1 2 2 1),
    (0 0 1 0 0 0 1 0 1 2 2),
    (0 0 0 1 0 0 2 1 0 1 2),
    (0 0 0 0 1 0 2 2 1 0 1),
    (0 0 0 0 0 1 1 2 2 1 0),
    (0 0 0 0 0 0 1 0 0 0 0),
    (0 0 0 0 0 0 0 1 0 0 0),
    (0 0 0 0 0 0 0 0 1 0 0),
    (0 0 0 0 0 0 0 0 0 1 0),
    (0 0 0 0 0 0 0 0 0 0 1)
]
> C3:= Complement(V11, G3);
> C3;
Vector space of degree 11, dimension 5 over GF(3)
Echelonized basis:
(0 0 0 0 0 0 1 0 0 0 0)
(0 0 0 0 0 0 0 1 0 0 0)
(0 0 0 0 0 0 0 0 1 0 0)
(0 0 0 0 0 0 0 0 0 1 0)
(0 0 0 0 0 0 0 0 0 0 1)
> G3 + C3;
Full Vector space of degree 11 over GF(3)
> G3 meet C3;
Vector space of degree 11, dimension 0 over GF(3)
> x := Random(G3);
> x;
(1 1 2 0 0 1 1 1 1 2 0)
> c := Coordinates(G3, x);
> c;
[ 1, 1, 2, 0, 0, 1 ]
> G3 ! &+[ c[i] * G3.i : i in [1 .. Dimension(G3)]];
(1 1 2 0 0 1 1 1 1 2 0)
```
