6.1 Vector Spaces

A vector space over the field F is an additive group that is closed under scalar multiplication with elements in F. In GAP, only those domains that are constructed as vector spaces are regarded as vector spaces . In particular, an additive group that does not know about an acting domain of scalars is not regarded as a vector space in GAP.

Probably the most common F-vector spaces in GAP are so-called row spaces. They consist of row vectors, that is, lists whose elements lie in F.

gap> F:= Rationals;;
gap> V:= VectorSpace( F, [ [ 1, 1, 1 ], [ 1, 0, 2 ] ] );
# The vector space spanned by [ 1, 1, 1] and [ 1, 0, 2 ].
<vector space over Rationals, with 2 generators>
gap> [ 2, 1, 3 ] in V;
true

The full row space Fn is created by commands like:

gap> F:= GF( 7 );;
gap> V:= F^3;                                           
# The full row space over F of dimension 3. 
( GF(7)^3 )
gap> [ 1, 2, 3 ] * One( F ) in V;  
true

In the same way we can also create matrix spaces. Here the short notation field^[dim1,dim2] can be used:

gap> m1:= [ [ 1, 2 ], [ 3, 4 ] ];; m2:= [ [ 0, 1 ], [ 1, 0 ] ];;
gap> V:= VectorSpace( Rationals, [ m1, m2 ] );
<vector space over Rationals, with 2 generators>
gap> m1+m2 in V;
true
gap> W:= Rationals^[3,2];
( Rationals^[ 3, 2 ] )
gap> [ [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] ] in W;
true

A field is naturally a vector space over itself.

gap> IsVectorSpace( Rationals );
true

If F is an algebraic extension of F, then F is also a vector space over F (and indeed over any subfield of F that contains F). This field F is stored in the attribute LeftActingDomain. In GAP, the default is to view fields as vector spaces over their prime fields. By the function AsVectorSpace, we can view fields as vector spaces over fields other than the prime field.

gap> F:= GF( 16 );;
gap> LeftActingDomain( F );
GF(2)
gap> G:= AsVectorSpace( GF( 4 ), F );       
AsField( GF(2^2), GF(2^4) )
gap> F = G;
true
gap> LeftActingDomain( G );
GF(2^2)

A vector space has three important attributes: its field of definition, its dimension and a basis. We already encountered the function LeftActingDomain in the example above. It extracts the field of definition of a vector space. The function Dimension provides the dimension of the space. Here is one more example.

gap> F:= GF( 9 );;
gap> m:= [ [ Z(3)^0, 0*Z(3), 0*Z(3) ], [ 0*Z(3), Z(3)^0, Z(3)^0 ] ];;
gap> V:= VectorSpace( F, m );
<vector space over GF(3^2), with 2 generators>
gap> Dimension( V );
2
gap> W:= AsVectorSpace( GF( 3 ), V );
<vector space over GF(3), with 4 generators>
gap> V = W;
true
gap> Dimension( W );
4
gap> LeftActingDomain( W );
GF(3)

One of the most important attributes is a basis. For a given basis B of V, every vector v in V can be expressed uniquely as v = åb Î B cb b, with coefficients cb Î F.

In GAP, bases are special lists of vectors. They are used mainly for the computation of coefficients and linear combinations.

Given a vector space V, a basis of V is obtained by simply applying the function Basis to V. The vectors that form the basis are extracted from the basis by BasisVectors.

gap> m1:= [ [ 1, 2 ], [ 3, 4 ] ];; m2:= [ [ 1, 1 ], [ 1, 0 ] ];;
gap> V:= VectorSpace( Rationals, [ m1, m2 ] );
<vector space over Rationals, with 2 generators>
gap> B:= Basis( V );
SemiEchelonBasis( <vector space over Rationals, with 2 generators>,... )
gap> BasisVectors( Basis( V ) );
[ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 0, 1 ], [ 2, 4 ] ] ]

The coefficients of a vector relative to a given basis are found by the function Coefficients. Furthermore, linear combinations of the basis vectors are constructed using LinearCombination.

gap> V:= VectorSpace( Rationals, [ [ 1, 2 ], [ 3, 4 ] ] );
<vector space over Rationals, with 2 generators>
gap> B:= Basis( V );
SemiEchelonBasis( <vector space over Rationals, with 2 generators>,... )
gap> BasisVectors( Basis( V ) );
[ [ 1, 2 ], [ 0, 1 ] ]
gap> Coefficients( B, [ 1, 0 ] );
[ 1, -2 ]
gap> LinearCombination( B, [ 1, -2 ] );
[ 1, 0 ]

In the above examples we have seen that GAP often chooses the basis it wants to work with. It is also possible to construct bases with prescribed basis vectors by giving a list of these vectors as second argument to Basis.

gap> V:= VectorSpace( Rationals, [ [ 1, 2 ], [ 3, 4 ] ] );; 
gap> B:= Basis( V, [ [ 1, 0 ], [ 0, 1 ] ] );
SemiEchelonBasis( <vector space over Rationals, with 2 generators>,
[ [ 1, 0 ], [ 0, 1 ] ] )
gap> Coefficients( B, [ 1, 2 ] );
[ 1, 2 ]

We can construct subspaces and quotient spaces of vector spaces. The natural projection map (constructed by NaturalHomomorphismBySubspace), connects a vector space with its quotient space.

gap> V:= Rationals^4;
( Rationals^4 )
gap> W:= Subspace( V, [ [ 1, 2, 3, 4 ], [ 0, 9, 8, 7 ] ] );
<vector space over Rationals, with 2 generators>
gap> VmodW:= V/W;
( Rationals^2 )
gap> h:= NaturalHomomorphismBySubspace( V, W );
<linear mapping by matrix, ( Rationals^4 ) -> ( Rationals^2 )>
gap> Image( h, [ 1, 2, 3, 4 ] );
[ 0, 0 ]
gap> PreImagesRepresentative( h, [ 1, 0 ] );
[ 1, 0, 0, 0 ]

[Top] [Up] [Next] [Index]

GAP 4 manual
February 2000