[Next] [Prev] [Right] [Left] [Up] [Index] [Root]
Creation of Vector Spaces and Arithmetic with Vectors

Creation of Vector Spaces and Arithmetic with Vectors

Subsections

Construction of a Vector Space

VectorSpace(K, n) : Fld, RngIntElt -> ModTupFld
KSpace(K, n) : Fld, RngIntElt -> ModTupFld
Given a field K and a positive 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, ..., e_n, where e_i (i = 1, ..., 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.

KModule(K, n) : Fld, RngIntElt -> ModTupFld
Given a field K and a positive 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, ..., e_n, where e_i (i = 1, ..., 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.

KMatrixSpace(K, m, n) : Fld, RngIntElt, RngIntElt -> ModMat
Given a field K and integers m and n greater than one, create the vector space K^((m x n)), consisting of all m x n matrices over K. The vector space is created with the standard basis, {E_(ij) | i = 1 ..., m, j = 1 ..., 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.

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

Example KMod_CreateQ6 (H41E1)

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

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

Example KMod_CreateK35 (H41E2)

We construct the matrix space M consisting of 3 x 5 matrices over the field Q(sqrt(5)).

> 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

elt<V | L> : ModTupFld, List -> ModTupFldElt
(1) Suppose V is a subspace of the vector space K^((n)). Given elements a_1, ..., a_n belonging to K, construct the vector v = (a_1, ..., 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 x n)). Given elements a_1, ..., a_(mn) belonging to K, construct the matrix m = (a_1, ..., a_(mn)) as an element of V. Note that if m is not an element of V, an error will result.

V ! Q : ModTupFld, [RngElt] -> ModTupFldElt
(1) Suppose V is a subspace of the vector space K^((n)). Given elements a_1, ..., a_n belonging to K, construct the vector v = (a_1, ..., 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 x n)). Given elements a_1, ..., a_(mn) belonging to K, construct the matrix m = (a_1, ..., a_(mn)) as an element of V. Note that if m is not an element of V, an error will result.

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.
V ! 0 : ModTupFld, RngIntElt -> ModTupFldElt
Zero(V) : ModTupFld, RngIntElt -> ModTupFldElt
The zero element for the vector space V.
Random(V) : ModTupFld -> ModTupFldElt
Given a vector space V defined over a finite field, return a random vector.

Example KMod_Vectors (H41E3)

We create the 5-dimensional vector space V over GF(4) and define the vector u = (1, w, 1 + w, 0, 0), where w is a primitive element of GF(4).

> 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)

Example KMod_Matrices (H41E4)

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

> 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

ElementToSequence(u) : ModTupFldElt -> [RngElt]
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 <= i <= 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 x n)). The scalar a must belong to the field K.

u + v : ModTupFldElt, ModTupFldElt -> ModTupFldElt
Sum of the vectors u and v, where u and v lie in the same vector space.
- u : ModTupFldElt -> ModTupFldElt
Additive inverse of the vector u.
u - v : ModTupFldElt, ModTupFldElt -> ModTupFldElt
Difference of the vectors u and v, where u and v lie in the same vector space.
x * u : FldElt, ModTupFldElt -> ModTupFldElt
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.
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.
NumberOfColumns(u) : ModTupFldElt -> RngIntElt
Ncols(u) : ModTupFldElt -> RngIntElt
The number of columns in the vector u.
Depth(u) : ModTupRngElt -> RngIntElt
The index of the first non-zero entry of the vector u (0 if none such).
(u, v) : ModTupFldElt, ModTupFldElt -> FldElt
InnerProduct(u, v) : ModTupFldElt, ModTupFldElt -> FldElt
Inner product of the vectors u and v with respect to the inner product defined on the space.
IsZero(u) : ModElt -> BoolElt
True iff the vector u belonging to a vector space is the zero element.
Normalise(u) : ModTupFldElt -> ModTupFldElt
Normalize(u) : ModTupFldElt -> ModTupFldElt
Given an element u, not the zero element, belonging to the K-vector space V, return (1/a) * u, where a is the first non-zero component of u. If u is the zero vector, it is returned as the value of this function. 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 is the unit of K.
Rotate(u, k) : ModTupFldElt, RngIntElt -> ModTupFldElt
Given a vector u, return the vector obtained from u by rotating by k coordinate positions.
Rotate(~u, k) : ModTupFldElt, RngIntElt ->
Given a vector u, destructively rotate u by k coordinate positions.
NumberOfRows(u) : ModTupFldElt -> RngIntElt
Nrows(u) : ModTupFldElt -> RngIntElt
The number of rows in the vector u (1 of course; included for completeness).
Support(u) : ModTupFldElt -> { RngElt }
A set of integers giving the positions of the non-zero components of the vector u.
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.
Trace(u, F) : ModTupFldElt, Fld -> ModTupFldElt
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.
Weight(u) : ModTupFldElt -> RngIntElt
The number of non-zero components of the vector u.

Example KMod_Arithmetic (H41E5)

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 Q(w), where w is an 8-th root of unity.

> 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;
((1 + w) (w + w^2) (-1 + w^2) -1)
> -x;
((-w) (-w^2)         1         0)
> x - y;
((-1 + w) (-w + w^2) (-1 - w^2) 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 - w^2 + w^3)
> z := V ! [1, 0, w, 0 ]; 
> z;
(       1        0 (w)        0)
> Support(z);
{ 1, 3 }

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.

u[i] : ModTupFldElt, RngIntElt -> RngElt
u[i] : ModTupFldElt, RngIntElt -> ModTupFldElt
u[i, j] : ModTupFldElt, RngIntElt, RngIntElt -> ModTupFldElt
Given an 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 <= i <= 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 x n)), and i, 1 <= i <= 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 <= i <= m, 1 <= j <= n, are positive integers, u[i, j] will return the (i, j)-th component of the matrix u (as an element of K).

u[i] : = x : ModTupFldElt, RngIntElt, RngElt -> ModTupFldElt
u[i] : = x : ModTupFldElt, RngIntElt, ModTupFldElt -> ModTupFldElt
u[i, j] : = x : ModTupFldElt, RngIntElt, RngIntElt, ModTupFldElt -> ModTupFldElt
Given an 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 <= i <= 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 x n)) and 1 <= i <= 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 <= i <= m, 1 <= j <= 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^((n)).


Example KMod_Indexing (H41E6)

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

> 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)]

[Next] [Prev] [Right] [Left] [Up] [Index] [Root]