############################################################################# ## #W vspc.gd GAP library Thomas Breuer ## ## #Y Copyright (C) 1997, Lehrstuhl D für Mathematik, RWTH Aachen, Germany #Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland #Y Copyright (C) 2002 The GAP Group ## ## This file declares the operations for vector spaces. ## ## The operations for bases of free left modules can be found in the file ## lib/basis.gd. ## ############################################################################# ## #C IsLeftOperatorRing() ## ## ## ## ## ## ## ## DeclareSynonym( "IsLeftOperatorRing", IsLeftOperatorAdditiveGroup and IsRing and IsAssociativeLOpDProd ); #T really? ############################################################################# ## #C IsLeftOperatorRingWithOne() ## ## ## ## ## ## ## ## DeclareSynonym( "IsLeftOperatorRingWithOne", IsLeftOperatorAdditiveGroup and IsRingWithOne and IsAssociativeLOpDProd ); #T really? ############################################################################# ## #C IsLeftVectorSpace( ) #C IsVectorSpace( ) ## ## <#GAPDoc Label="IsLeftVectorSpace"> ## ## ## ## ## ## A vector space in &GAP; is a free left module ## (see ) over a division ring ## (see Chapter ). ##

## Whenever we talk about an F-vector space V then V is ## an additive group (see ) on which the ## division ring F acts via multiplication from the left such that ## this action and the addition in V are left and right distributive. ## The division ring F can be accessed as value of the attribute ## . ##

## Vector spaces in &GAP; are always left vector spaces, ## and are ## synonyms. ## ## ## <#/GAPDoc> ## DeclareSynonym( "IsLeftVectorSpace", IsLeftModule and IsLeftActedOnByDivisionRing ); DeclareSynonym( "IsVectorSpace", IsLeftVectorSpace ); InstallTrueMethod( IsFreeLeftModule, IsLeftModule and IsLeftActedOnByDivisionRing ); ############################################################################# ## #F IsGaussianSpace( ) ## ## <#GAPDoc Label="IsGaussianSpace"> ## ## ## ## ## The filter (see ) ## for the row space (see ) ## or matrix space (see ) V ## over the field F, say, ## indicates that the entries of all row vectors or matrices in V, ## respectively, are all contained in F. ## In this case, V is called a Gaussian vector space. ## Bases for Gaussian spaces can be computed using Gaussian elimination for ## a given list of vector space generators. ## mats:= [ [[1,1],[2,2]], [[3,4],[0,1]] ];; ## gap> V:= VectorSpace( Rationals, mats );; ## gap> IsGaussianSpace( V ); ## true ## gap> mats[1][1][1]:= E(4);; # an element in an extension field ## gap> V:= VectorSpace( Rationals, mats );; ## gap> IsGaussianSpace( V ); ## false ## gap> V:= VectorSpace( Field( Rationals, [ E(4) ] ), mats );; ## gap> IsGaussianSpace( V ); ## true ## ]]> ## ## ## <#/GAPDoc> ## DeclareFilter( "IsGaussianSpace", IsVectorSpace ); InstallTrueMethod( IsGaussianSpace, IsVectorSpace and IsFullMatrixModule ); InstallTrueMethod( IsGaussianSpace, IsVectorSpace and IsFullRowModule ); ############################################################################# ## #C IsDivisionRing( ) ## ## <#GAPDoc Label="IsDivisionRing"> ## ## ## ## ## A division ring in &GAP; is a nontrivial associative algebra ## D with a multiplicative inverse for each nonzero element. ## In &GAP; every division ring is a vector space over a division ring ## (possibly over itself). ## Note that being a division ring is thus not a property that a ring can ## get, because a ring is usually not represented as a vector space. ##

## The field of coefficients is stored as the value of the attribute ## of D. ## ## ## <#/GAPDoc> ## DeclareSynonymAttr( "IsDivisionRing", IsMagmaWithInversesIfNonzero and IsLeftOperatorRingWithOne and IsLeftVectorSpace and IsNonTrivial and IsAssociative and IsEuclideanRing ); ############################################################################# ## #A GeneratorsOfLeftVectorSpace( ) #A GeneratorsOfVectorSpace( ) ## ## <#GAPDoc Label="GeneratorsOfLeftVectorSpace"> ## ## ## ## ## ## For an F-vector space V, ## returns a list of vectors in ## V that generate V as an F-vector space. ## GeneratorsOfVectorSpace( FullRowSpace( Rationals, 3 ) ); ## [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonymAttr( "GeneratorsOfLeftVectorSpace", GeneratorsOfLeftOperatorAdditiveGroup ); DeclareSynonymAttr( "GeneratorsOfVectorSpace", GeneratorsOfLeftOperatorAdditiveGroup ); ############################################################################# ## #A CanonicalBasis( ) ## ## <#GAPDoc Label="CanonicalBasis"> ## ## ## ## ## If the vector space V supports a canonical basis then ## returns this basis, ## otherwise fail is returned. ##

## The defining property of a canonical basis is that its vectors are ## uniquely determined by the vector space. ## If canonical bases exist for two vector spaces over the same left acting ## domain (see ) then the equality of ## these vector spaces can be decided by comparing the canonical bases. ##

## The exact meaning of a canonical basis depends on the type of V. ## Canonical bases are defined for example for Gaussian row and matrix ## spaces (see ). ##

## If one designs a new kind of vector spaces ## (see ) and ## defines a canonical basis for these spaces then the ## method one installs ## (see ) ## must not call . ## On the other hand, one probably should install a ## method that simply calls , ## the value of the method ## (see  and ## ) ## being CANONICAL_BASIS_FLAGS. ## vecs:= [ [ 1, 2, 3 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ];; ## gap> V:= VectorSpace( Rationals, vecs );; ## gap> B:= CanonicalBasis( V ); ## CanonicalBasis( ) ## gap> BasisVectors( B ); ## [ [ 1, 0, -1 ], [ 0, 1, 2 ] ] ## ]]> ## ## ## <#/GAPDoc> ## DeclareAttribute( "CanonicalBasis", IsFreeLeftModule ); ############################################################################# ## #F IsRowSpace( ) ## ## <#GAPDoc Label="IsRowSpace"> ## ## ## ## ## A row space in &GAP; is a vector space that consists of ## row vectors (see Chapter ). ## ## ## <#/GAPDoc> ## DeclareSynonym( "IsRowSpace", IsRowModule and IsVectorSpace ); ############################################################################# ## #F IsGaussianRowSpace( ) ## ## ## ## ## ## A row space is Gaussian if the left acting domain contains all ## scalars that occur in the vectors. ## Thus one can use Gaussian elimination in the calculations. ##

## (Otherwise the space is non-Gaussian. ## We will need a flag for this to write down methods that delegate from ## non-Gaussian spaces to Gaussian ones.) ## ## ## ## DeclareSynonym( "IsGaussianRowSpace", IsGaussianSpace and IsRowSpace ); ############################################################################# ## #F IsNonGaussianRowSpace( ) ## ## ## ## ## ## If an F-vector space V is in the filter ## then this expresses that V ## consists of row vectors (see ) such ## that not all entries in these row vectors are contained in F ## (so Gaussian elimination cannot be used to compute an F-basis ## from a list of vector space generators), ## and that V is handled via the mechanism of nice bases ## (see ) in the following way. ## Let K be the field spanned by the entries of all vectors in ## V. ## Then the value of V is ## a basis B of the field extension K / ( K \cap F ), ## and the value of v \in V ## is defined by replacing each entry of v by the list of its ## B-coefficients, and then forming the concatenation. ##

## So the associated nice vector space is a Gaussian row space ## (see ). ## ## ## DeclareHandlingByNiceBasis( "IsNonGaussianRowSpace", "for non-Gaussian row spaces" ); ############################################################################# ## #F IsMatrixSpace( ) ## ## <#GAPDoc Label="IsMatrixSpace"> ## ## ## ## ## A matrix space in &GAP; is a vector space that consists of matrices ## (see Chapter ). ## ## ## <#/GAPDoc> ## DeclareSynonym( "IsMatrixSpace", IsMatrixModule and IsVectorSpace ); ############################################################################# ## #F IsGaussianMatrixSpace( ) ## ## ## ## ## ## A matrix space is Gaussian if the left acting domain contains all ## scalars that occur in the vectors. ## Thus one can use Gaussian elimination in the calculations. ##

## (Otherwise the space is non-Gaussian. ## We will need a flag for this to write down methods that delegate from ## non-Gaussian spaces to Gaussian ones.) ## ## ## DeclareSynonym( "IsGaussianMatrixSpace", IsGaussianSpace and IsMatrixSpace ); ############################################################################# ## #F IsNonGaussianMatrixSpace( ) ## ## ## ## ## ## If an F-vector space V is in the filter ## ## then this expresses that V consists of matrices ## (see ) ## such that not all entries in these matrices are contained in F ## (so Gaussian elimination cannot be used to compute an F-basis ## from a list of vector space generators), ## and that V is handled via the mechanism of nice bases ## (see ) in the following way. ## Let K be the field spanned by the entries of all vectors in V. ## The value of V is irrelevant, ## and the value of v \in V ## is defined as the concatenation of the rows of v. ##

## So the associated nice vector space is a (not necessarily Gaussian) ## row space (see ). ## ## ## DeclareHandlingByNiceBasis( "IsNonGaussianMatrixSpace", "for non-Gaussian matrix spaces" ); ############################################################################# ## #A NormedRowVectors( ) . . . normed vectors in a Gaussian row space ## ## <#GAPDoc Label="NormedRowVectors"> ## ## ## ## ## For a finite Gaussian row space V ## (see , ), ## returns a list of those nonzero ## vectors in V that have a one in the first nonzero component. ##

## The result list can be used as action domain for the action of a matrix ## group via , which yields the natural action on ## one-dimensional subspaces of V ## (see also ). ## vecs:= NormedRowVectors( GF(3)^2 ); ## [ [ 0*Z(3), Z(3)^0 ], [ Z(3)^0, 0*Z(3) ], [ Z(3)^0, Z(3)^0 ], ## [ Z(3)^0, Z(3) ] ] ## gap> Action( GL(2,3), vecs, OnLines ); ## Group([ (3,4), (1,2,4) ]) ## ]]> ## ## ## <#/GAPDoc> ## DeclareAttribute( "NormedRowVectors", IsGaussianSpace ); ############################################################################# ## #A TrivialSubspace( ) ## ## <#GAPDoc Label="TrivialSubspace"> ## ## ## ## ## For a vector space V, returns the ## subspace of V that consists of the zero vector in V. ## V:= GF(3)^3;; ## gap> triv:= TrivialSubspace( V ); ## ## gap> AsSet( triv ); ## [ [ 0*Z(3), 0*Z(3), 0*Z(3) ] ] ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonymAttr( "TrivialSubspace", TrivialSubmodule ); ############################################################################# ## #F VectorSpace( , [, ][, "basis"] ) ## ## <#GAPDoc Label="VectorSpace"> ## ## ## ## ## For a field F and a collection gens of vectors, ## returns the F-vector space spanned by ## the elements in gens. ##

## The optional argument zero can be used to specify the zero element ## of the space; zero must be given if gens is empty. ## The optional string "basis" indicates that gens is known to ## be linearly independent over F, in particular the dimension of the ## vector space is immediately set; ## note that need not return the basis formed by ## gens if the string "basis" is given as an argument. ## ## V:= VectorSpace( Rationals, [ [ 1, 2, 3 ], [ 1, 1, 1 ] ] ); ## ## ]]> ## ## ## <#/GAPDoc> ## DeclareGlobalFunction( "VectorSpace" ); ############################################################################# ## #F Subspace( , [, "basis"] ) . subspace of generated by #F SubspaceNC( , [, "basis"] ) ## ## <#GAPDoc Label="Subspace"> ## ## ## ## ## ## For an F-vector space V and a list or collection ## gens that is a subset of V, ## returns the F-vector space spanned by ## gens; if gens is empty then the trivial subspace ## (see ) of V is returned. ## The parent (see ) of the returned vector space ## is set to V. ##

## does the same as , ## except that it omits the check whether gens is a subset of ## V. ##

## The optional string "basis" indicates that gens is known to ## be linearly independent over F. ## In this case the dimension of the subspace is immediately set, ## and both and do ## not check whether gens really is linearly independent and ## whether gens is a subset of V. ## ## V:= VectorSpace( Rationals, [ [ 1, 2, 3 ], [ 1, 1, 1 ] ] );; ## gap> W:= Subspace( V, [ [ 0, 1, 2 ] ] ); ## ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonym( "Subspace", Submodule ); DeclareSynonym( "SubspaceNC", SubmoduleNC ); ############################################################################# ## #O AsVectorSpace( , ) . . . . . . . . . view as -vector space ## ## <#GAPDoc Label="AsVectorSpace"> ## ## ## ## ## Let F be a division ring and D a domain. ## If the elements in D form an F-vector space then ## returns this F-vector space, ## otherwise fail is returned. ##

## can be used for example to view a given ## vector space as a vector space over a smaller or larger division ring. ## V:= FullRowSpace( GF( 27 ), 3 ); ## ( GF(3^3)^3 ) ## gap> Dimension( V ); LeftActingDomain( V ); ## 3 ## GF(3^3) ## gap> W:= AsVectorSpace( GF( 3 ), V ); ## ## gap> Dimension( W ); LeftActingDomain( W ); ## 9 ## GF(3) ## gap> AsVectorSpace( GF( 9 ), V ); ## fail ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonym( "AsVectorSpace", AsLeftModule ); ############################################################################# ## #O AsSubspace( , ) . . . . . . . . . . . view as subspace of ## ## <#GAPDoc Label="AsSubspace"> ## ## ## ## ## Let V be an F-vector space, and U a collection. ## If U is a subset of V such that the elements of U ## form an F-vector space then returns this ## vector space, with parent set to V ## (see ). ## Otherwise fail is returned. ## V:= VectorSpace( Rationals, [ [ 1, 2, 3 ], [ 1, 1, 1 ] ] );; ## gap> W:= VectorSpace( Rationals, [ [ 1/2, 1/2, 1/2 ] ] );; ## gap> U:= AsSubspace( V, W ); ## ## gap> Parent( U ) = V; ## true ## gap> AsSubspace( V, [ [ 1, 1, 1 ] ] ); ## fail ## ]]> ## ## ## <#/GAPDoc> ## DeclareOperation( "AsSubspace", [ IsVectorSpace, IsCollection ] ); ############################################################################# ## #F Intersection2Spaces( , , ) ## ## ## ## ## ## is a function that takes two arguments V and W which must ## be finite dimensional vector spaces, ## and returns the intersection of V and W. ##

## If the left acting domains are different then let F be their ## intersection. ## The intersection of V and W is computed as intersection of ## AsStruct( F, V ) and ## AsStruct( F, V ). ##

## If the left acting domains are equal to F then the intersection of ## V and W is returned either as F-Substruct ## with the common parent of V and W or as ## F-Struct, in both cases with known basis. ##

## This function is used to handle the intersections of two vector spaces, ## two algebras, two algebras-with-one, two left ideals, two right ideals, ## two two-sided ideals. ## ## ## DeclareGlobalFunction( "Intersection2Spaces" ); ############################################################################# ## #F FullRowSpace( , ) ## ## <#GAPDoc Label="FullRowSpace"> ## ## ## ## ## ## For a field F and a nonnegative integer n, ## returns the F-vector space that ## consists of all row vectors (see ) of ## length n with entries in F. ##

## An alternative to construct this vector space is via ## F^n. ## FullRowSpace( GF( 9 ), 3 ); ## ( GF(3^2)^3 ) ## gap> GF(9)^3; # the same as above ## ( GF(3^2)^3 ) ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonym( "FullRowSpace", FullRowModule ); DeclareSynonym( "RowSpace", FullRowModule ); ############################################################################# ## #F FullMatrixSpace( , , ) ## ## <#GAPDoc Label="FullMatrixSpace"> ## ## ## ## ## ## For a field F and two positive integers m and n, ## returns the F-vector space that ## consists of all m by n matrices ## (see ) with entries in F. ##

## If m = n then the result is in fact an algebra ## (see ). ##

## An alternative to construct this vector space is via ## F^[m,n]. ## FullMatrixSpace( GF(2), 4, 5 ); ## ( GF(2)^[ 4, 5 ] ) ## gap> GF(2)^[ 4, 5 ]; # the same as above ## ( GF(2)^[ 4, 5 ] ) ## ]]> ## ## ## <#/GAPDoc> ## DeclareSynonym( "FullMatrixSpace", FullMatrixModule ); DeclareSynonym( "MatrixSpace", FullMatrixModule ); DeclareSynonym( "MatSpace", FullMatrixModule ); ############################################################################# ## #C IsSubspacesVectorSpace( ) ## ## <#GAPDoc Label="IsSubspacesVectorSpace"> ## ## ## ## ## The domain of all subspaces of a (finite) vector space or of all ## subspaces of fixed dimension, as returned by ## (see ) lies in the category ## . ## D:= Subspaces( GF(3)^3 ); ## Subspaces( ( GF(3)^3 ) ) ## gap> Size( D ); ## 28 ## gap> iter:= Iterator( D );; ## gap> NextIterator( iter ); ## ## gap> NextIterator( iter ); ## ## gap> IsSubspacesVectorSpace( D ); ## true ## ]]> ## ## ## <#/GAPDoc> ## DeclareCategory( "IsSubspacesVectorSpace", IsDomain ); ############################################################################# ## #M IsFinite( ) . . . . . . . . . . . . . . . . . for a subspaces domain ## ## Returns `true' if is finite. ## We allow subspaces domains in `IsSubspacesVectorSpace' only for finite ## vector spaces. ## InstallTrueMethod( IsFinite, IsSubspacesVectorSpace ); ############################################################################# ## #A Subspaces( [, ] ) ## ## <#GAPDoc Label="Subspaces"> ## ## ## ## ## Called with a finite vector space v, ## returns the domain of all subspaces of V. ##

## Called with V and a nonnegative integer k, ## returns the domain of all k-dimensional ## subspaces of V. ##

## Special and methods are ## provided for these domains. ## ## ## ## <#/GAPDoc> ## DeclareAttribute( "Subspaces", IsLeftModule ); DeclareOperation( "Subspaces", [ IsLeftModule, IsInt ] ); ############################################################################# ## #F IsSubspace( , ) ## ## ## ## ## ## check that U is a vector space that is contained in V ## ## ## ## DeclareGlobalFunction( "IsSubspace" ); ############################################################################# ## #A OrthogonalSpaceInFullRowSpace( ) ## ## ## ## ## ## For a Gaussian row space U over F, ## ## returns a complement of U in the full row space of same vector ## dimension as U over F. ## ## ## DeclareAttribute( "OrthogonalSpaceInFullRowSpace", IsGaussianSpace ); ############################################################################# ## #P IsVectorSpaceHomomorphism( ) ## ## ## ## ## ## A mapping f is a vector space homomorphism (or linear mapping) ## if the source and range are vector spaces ## (see ) ## over the same division ring D ## (see ), ## and if f( a + b ) = f(a) + f(b) and f( s * a ) = s * f(a) ## hold for all elements a, b in the source of f and ## s \in D. ## ## ## DeclareProperty( "IsVectorSpaceHomomorphism", IsGeneralMapping ); ############################################################################# ## #E