Function: Vec
Section: conversions
C-Name: gtovec0
Prototype: GD0,L,
Help: Vec(x,{n}): transforms the object x into a vector of dimension n.
Description:
 (gen):vec        gtovec($1)
Doc: transforms the object $x$ into a row vector. The dimension of the
 resulting vector can be optionally specified via the extra parameter $n$.
 If $n$ is omitted or $0$, the dimension depends on the type of $x$; the
 vector has a single component, except when $x$ is

 \item a vector or a quadratic form: returns the initial object considered as a
 row vector,

 \item a polynomial or a power series: returns a vector consisting of the
 coefficients. In the case of a polynomial, the coefficients of the vector
 start with the leading coefficient of the polynomial, while for power series
 only the significant coefficients are taken into account, but this time by
 increasing order of degree. In particular the valuation is ignored
 (which makes the function useful for series of negative valuation):
 \bprog
 ? Vec(3*x^2 + x)
 %1 = [3, 1, 0]
 ? Vec(x^2 + 3*x^3 + O(x^5))
 %2 = [1, 3, 0]
 ? Vec(x^-2 + 3*x^-1 + O(x))
 %3 = [1, 3, 0]
 @eprog\noindent \kbd{Vec} is the reciprocal function of \kbd{Pol} for a
 polynomial and of \kbd{Ser} for power series of valuation $0$.

 \item a matrix: returns the vector of columns comprising the matrix,
 \bprog
 ? m = [1,2,3;4,5,6]
 %4 =
 [1 2 3]

 [4 5 6]
 ? Vec(m)
 %5 = [[1, 4]~, [2, 5]~, [3, 6]~]
 @eprog

 \item a character string: returns the vector of individual characters
 (as strings of length $1$),
 \bprog
 ? Vec("PARI")
 %6 = ["P", "A", "R", "I"]
 @eprog

 \item a map: returns the vector of the domain of the map,
 \bprog
 ? M = Map(matreduce(primes([1,20])))
 %7 = Map([2, 1; 3, 1; 5, 1; 7, 1; 11, 1; 13, 1; 17, 1; 19, 1])
 ? Vec(M)==select(i->mapisdefined(M,i), [1..20])
 %8 = 1
 @eprog

 \item an error context (\typ{ERROR}): returns the error components, see
 \tet{iferr}.

 In the last four cases (matrix, character string, map, error), $n$ is
 meaningless and must be omitted or an error is raised. Otherwise, if $n$ is
 given, $0$ entries are appended at the end of the vector if $n > 0$, and
 prepended at the beginning if $n < 0$. The dimension of the resulting vector
 is $|n|$. If the original object had more than $|n|$ components, it is
 truncated from the right if $n > 0$ and from the left if $n < 0$:
 \bprog
 ? v = [1,2,3,4];
 ? forstep(i=5, 2, -1, print(Vec(v, i)));
 [1, 2, 3, 4, 0]
 [1, 2, 3, 4]
 [1, 2, 3]  \\ truncated from the right
 [1, 2]

 ? forstep(i=5, 2, -1, print(Vec(v, -i)));
 [0, 1, 2, 3, 4]
 [1, 2, 3, 4]
 [2, 3, 4]  \\ truncated from the left
 [3, 4]
 @eprog

 These rules allow to write a conversion function for series that takes
 positive valuations into account:
 \bprog
 ? serVec(s) = Vec(s, -serprec(s,variable(s)));
 ? serVec(x^2 + 3*x^3 + O(x^5))
 %2 = [0, 0, 1, 3, 0]
 @eprog\noindent (That function is not intended for series of negative
 valuation.)

Variant: \fun{GEN}{gtovec}{GEN x} is also available.
