Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

23 Row Vectors
 23.1 IsRowVector (Filter)
 23.2 Operators for Row Vectors
 23.3 Row Vectors over Finite Fields
 23.4 Coefficient List Arithmetic
 23.5 Shifting and Trimming Coefficient Lists
 23.6 Functions for Coding Theory
 23.7 Vectors as coefficients of polynomials

23 Row Vectors

Just as in mathematics, a vector in GAP is any object which supports appropriate addition and scalar multiplication operations (see Chapter 61). As in mathematics, an especially important class of vectors are those represented by a list of coefficients with respect to some basis. These correspond roughly to the GAP concept of row vectors.

23.1 IsRowVector (Filter)

23.1-1 IsRowVector
‣ IsRowVector( obj )( category )

A row vector is a vector (see IsVector (31.14-14)) that is also a homogeneous list of odd additive nesting depth (see 21.12). Typical examples are lists of integers and rationals, lists of finite field elements of the same characteristic, and lists of polynomials from a common polynomial ring. Note that matrices are not regarded as row vectors, because they have even additive nesting depth.

The additive operations of the vector must thus be compatible with that for lists, implying that the list entries are the coefficients of the vector with respect to some basis.

Note that not all row vectors admit a multiplication via * (which is to be understood as a scalar product); for example, class functions are row vectors but the product of two class functions is defined in a different way. For the installation of a scalar product of row vectors, the entries of the vector must be ring elements; note that the default method expects the row vectors to lie in IsRingElementList, and this category may not be implied by IsRingElement (31.14-16) for all entries of the row vector (see the comment in IsVector (31.14-14)).

Note that methods for special types of row vectors really must be installed with the requirement IsRowVector, since IsVector (31.14-14) may lead to a rank of the method below that of the default method for row vectors (see file lib/vecmat.gi).

gap> IsRowVector([1,2,3]);
true

Because row vectors are just a special case of lists, all operations and functions for lists are applicable to row vectors as well (see Chapter 21). This especially includes accessing elements of a row vector (see 21.3), changing elements of a mutable row vector (see 21.4), and comparing row vectors (see 21.10).

Note that, unless your algorithms specifically require you to be able to change entries of your vectors, it is generally better and faster to work with immutable row vectors. See Section 12.6 for more details.

23.2 Operators for Row Vectors

The rules for arithmetic operations involving row vectors are in fact special cases of those for the arithmetic of lists, as given in Section 21.11 and the following sections, here we reiterate that definition, in the language of vectors.

Note that the additive behaviour sketched below is defined only for lists in the category IsGeneralizedRowVector (21.12-1), and the multiplicative behaviour is defined only for lists in the category IsMultiplicativeGeneralizedRowVector (21.12-2).

vec1 + vec2

returns the sum of the two row vectors vec1 and vec2. Probably the most usual situation is that vec1 and vec2 have the same length and are defined over a common field; in this case the sum is a new row vector over the same field where each entry is the sum of the corresponding entries of the vectors.

In more general situations, the sum of two row vectors need not be a row vector, for example adding an integer vector vec1 and a vector vec2 over a finite field yields the list of pointwise sums, which will be a mixture of finite field elements and integers if vec1 is longer than vec2.

scalar + vec

vec + scalar

returns the sum of the scalar scalar and the row vector vec. Probably the most usual situation is that the elements of vec lie in a common field with scalar; in this case the sum is a new row vector over the same field where each entry is the sum of the scalar and the corresponding entry of the vector.

More general situations are for example the sum of an integer scalar and a vector over a finite field, or the sum of a finite field element and an integer vector.

gap> [ 1, 2, 3 ] + [ 1/2, 1/3, 1/4 ];
[ 3/2, 7/3, 13/4 ]
gap>  [ 1/2, 3/2, 1/2 ] + 1/2;
[ 1, 2, 1 ]

vec1 - vec2

scalar - vec

vec - scalar

Subtracting a vector or scalar is defined as adding its additive inverse, so the statements for the addition hold likewise.

gap> [ 1, 2, 3 ] - [ 1/2, 1/3, 1/4 ];
[ 1/2, 5/3, 11/4 ]
gap> [ 1/2, 3/2, 1/2 ] - 1/2;
[ 0, 1, 0 ]

scalar * vec

vec * scalar

returns the product of the scalar scalar and the row vector vec. Probably the most usual situation is that the elements of vec lie in a common field with scalar; in this case the product is a new row vector over the same field where each entry is the product of the scalar and the corresponding entry of the vector.

More general situations are for example the product of an integer scalar and a vector over a finite field, or the product of a finite field element and an integer vector.

gap> [ 1/2, 3/2, 1/2 ] * 2;
[ 1, 3, 1 ]

vec1 * vec2

returns the standard scalar product of vec1 and vec2, i.e., the sum of the products of the corresponding entries of the vectors. Probably the most usual situation is that vec1 and vec2 have the same length and are defined over a common field; in this case the sum is an element of this field.

More general situations are for example the inner product of an integer vector and a vector over a finite field, or the inner product of two row vectors of different lengths.

gap> [ 1, 2, 3 ] * [ 1/2, 1/3, 1/4 ];
23/12

For the mutability of results of arithmetic operations, see 12.6.

Further operations with vectors as operands are defined by the matrix operations, see 24.3.

23.2-1 NormedRowVector
<
‣ NormedRowVector( v )