<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %A  vector.xml                  GAP documentation            Martin Schönert -->
<!-- %A                                                           Alexander Hulpke -->
<!-- %% -->
<!-- %% -->
<!-- %Y  (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland -->
<!-- %Y  Copyright (C) 2002 The GAP Group -->
<!-- %% -->
<Chapter Label="Row Vectors">
<Heading>Row Vectors</Heading>

Just as in mathematics, a vector in &GAP; is any object which
supports appropriate addition and scalar multiplication operations
(see Chapter&nbsp;<Ref Chap="Vector Spaces"/>).
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 <E>row vectors</E>.

<!-- %%  The basic design of the row vector support in &GAP; 4 is due to -->
<!-- %%  Martin Schönert. Frank Celler added the special support for -->
<!-- %%  vectors over the field of two elements; Steve Linton added special -->
<!-- %%  support for vectors over fields of sizes between 3 and 256; and Werner -->
<!-- %%  Nickel added special methods for vectors over large finite fields. -->


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="sect:IsRowVector">
<Heading>IsRowVector (Filter)</Heading>

<#Include Label="IsRowVector">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Operators for Row Vectors">
<Heading>Operators for Row Vectors</Heading>

The rules for arithmetic operations involving row vectors are in fact
special cases of those for the arithmetic of lists,
as given in Section&nbsp;<Ref Sect="Arithmetic for Lists"/>
and the following sections,
here we reiterate that definition, in the language of vectors.
<P/>
Note that the additive behaviour sketched below is defined only for lists in
the category <Ref Filt="IsGeneralizedRowVector"/>,
and the multiplicative behaviour is defined only for lists in the category
<Ref Filt="IsMultiplicativeGeneralizedRowVector"/>.
<P/>
<Index Subkey="vectors">addition</Index>
<C><A>vec1</A> + <A>vec2</A></C>
<P/>
returns the sum of the two row vectors <A>vec1</A> and <A>vec2</A>.
Probably the most usual situation is that <A>vec1</A> and <A>vec2</A> 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.
<P/>
In more general situations, the sum of two row vectors need not be a row
vector, for example adding an integer vector <A>vec1</A> and a vector
<A>vec2</A> over a finite field yields the list of pointwise sums,
which will be a mixture of finite field elements and integers if <A>vec1</A>
is longer than <A>vec2</A>.
<P/>
<Index Subkey="vector and scalar">addition</Index>
<C><A>scalar</A> + <A>vec</A></C>
<P/>
<C><A>vec</A> + <A>scalar</A></C>
<P/>
returns the sum of the scalar <A>scalar</A> and the row vector <A>vec</A>.
Probably the most usual situation is that the elements of <A>vec</A> lie in a
common field with <A>scalar</A>;
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.
<P/>
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.
<P/>
<Example><![CDATA[
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 ]
]]></Example>
<P/>
<Index Subkey="vectors">subtraction</Index>
<Index Subkey="scalar and vector">subtraction</Index>
<Index Subkey="vector and scalar">subtraction</Index>
<C><A>vec1</A> - <A>vec2</A></C>
<P/>
<C><A>scalar</A> - <A>vec</A></C>
<P/>
<C><A>vec</A> - <A>scalar</A></C>
<P/>
Subtracting a vector or scalar is defined as adding its additive inverse,
so the statements for the addition hold likewise.
<P/>
<Example><![CDATA[
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 ]
]]></Example>
<P/>
<Index Subkey="scalar and vector">multiplication</Index>
<Index Subkey="vector and scalar">multiplication</Index>
<C><A>scalar</A> * <A>vec</A></C>
<P/>
<C><A>vec</A> * <A>scalar</A></C>
<P/>
returns the product of the scalar <A>scalar</A> and the row vector <A>vec</A>.
Probably the most usual situation is that the elements of <A>vec</A> lie in a
common field with <A>scalar</A>;
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.
<P/>
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.
<P/>
<Example><![CDATA[
gap> [ 1/2, 3/2, 1/2 ] * 2;
[ 1, 3, 1 ]
]]></Example>
<P/>
<Index Subkey="vectors">multiplication</Index>
<C><A>vec1</A> * <A>vec2</A></C>
<P/>
returns the standard scalar product of <A>vec1</A> and <A>vec2</A>,
i.e., the sum of the products of the corresponding entries of the vectors.
Probably the most usual situation is that <A>vec1</A> and <A>vec2</A> have
the same length and are defined over a common field;
in this case the sum is an element of this field.
<P/>
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.
<P/>
<Example><![CDATA[
gap> [ 1, 2, 3 ] * [ 1/2, 1/3, 1/4 ];
23/12
]]></Example>
<P/>
For the mutability of results of arithmetic operations,
see&nbsp;<Ref Sect="Mutability and Copyability"/>.
<P/>
Further operations with vectors as operands are defined by the matrix
operations, see&nbsp;<Ref Sect="Operators for Matrices"/>.

<#Include Label="NormedRowVector">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Row Vectors over Finite Fields">
<Heading>Row Vectors over Finite Fields</Heading>

&GAP; can use compact formats to store row vectors over fields of
order at most 256, based on those used by the Meat-Axe
<Cite Key="Rin93"/>. This format also permits extremely efficient vector
arithmetic. On the other hand element access and assignment is
significantly slower than for plain lists.
<P/>
The function
<Ref Func="ConvertToVectorRep" Label="for a list (and a field)"/> is used to
convert a list into a compressed vector, or to rewrite a compressed vector
over another field.
Note that this function is <E>much</E> faster when it is given a
field (or field size) as an argument, rather than having to scan the
vector and try to decide the field. Supplying the field can also
avoid errors and/or loss of performance, when one vector from some
collection happens to have all of its entries over a smaller field
than the <Q>natural</Q> field of the problem.

<#Include Label="ConvertToVectorRep">
<#Include Label="ImmutableVector">
<#Include Label="NumberFFVector">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Coefficient List Arithmetic">
<Heading>Coefficient List Arithmetic</Heading>

<#Include Label="[1]{listcoef}">
<#Include Label="AddRowVector">
<#Include Label="AddCoeffs">
<#Include Label="MultVector">
<#Include Label="CoeffsMod">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Shifting and Trimming Coefficient Lists">
<Heading>Shifting and Trimming Coefficient Lists</Heading>

<#Include Label="[3]{listcoef}">
<#Include Label="LeftShiftRowVector">
<#Include Label="RightShiftRowVector">
<#Include Label="ShrinkRowVector">
<#Include Label="RemoveOuterCoeffs">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Functions for Coding Theory">
<Heading>Functions for Coding Theory</Heading>

<#Include Label="[4]{listcoef}">
<#Include Label="WeightVecFFE">
<#Include Label="DistanceVecFFE">
<#Include Label="DistancesDistributionVecFFEsVecFFE">
<#Include Label="DistancesDistributionMatFFEVecFFE">
<#Include Label="AClosestVectorCombinationsMatFFEVecFFE">
<#Include Label="CosetLeadersMatFFE">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Vectors as coefficients of polynomials">
<Heading>Vectors as coefficients of polynomials</Heading>

A list of ring elements can be interpreted as a row vector or the list of
coefficients of a polynomial. There are a couple of functions that implement
arithmetic operations based on these interpretations. &GAP; contains proper
support for polynomials (see&nbsp;<Ref Chap="Polynomials and Rational Functions"/>), the
operations described in this section are on a lower level.
<P/>
<#Include Label="[2]{listcoef}">
<#Include Label="ValuePol">

<!-- %\ Declaration{MultCoeffs} -->
<!-- %\ beginexample -->
<!-- %gap> a:=[];;l:=[1,2,3,4];;m:=[5,6,7];; -->
<!-- %gap> MultCoeffs(a,l,4,m,3); -->
<!-- %6 -->
<!-- %gap> a; -->
<!-- %[ 5, 16, 34, 52, 45, 28 ] -->
<!-- %\ endexample -->

<#Include Label="ProductCoeffs">
<#Include Label="ReduceCoeffs">
<#Include Label="ReduceCoeffsMod">
<#Include Label="PowerModCoeffs">
<#Include Label="ShiftedCoeffs">

</Section>
</Chapter>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %E -->

