[BACK]Return to array.texi CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / parts / builtin

File: [local] / OpenXM / src / asir-doc / parts / builtin / array.texi (download)

Revision 1.15, Fri Dec 9 05:18:41 2011 UTC (12 years, 6 months ago) by nisiyama
Branch: MAIN
CVS Tags: RELEASE_1_3_1_13b, HEAD
Changes since 1.14: +3 -3 lines

*** empty log message ***

@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/array.texi,v 1.15 2011/12/09 05:18:41 nisiyama Exp $
\BJP
@node $BG[Ns(B,,, $BAH$_9~$_H!?t(B
@section $BG[Ns(B
\E
\BEG
@node Arrays,,, Built-in Function
@section Arrays
\E

@menu
* newvect vector vect::
* ltov::
* vtol::
* newbytearray::
* newmat matrix::
* mat matr matc::
* size::
* det nd_det invmat::
* rowx rowm rowa colx colm cola::

* qsort::
@end menu

\JP @node newvect vector vect,,, $BG[Ns(B
\EG @node newvect vector vect,,, Arrays
@subsection @code{newvect}, @code{vector}, @code{vect}
@findex newvect
@findex vector
@findex vect

@table @t
@item newvect(@var{len}[,@var{list}])
@item vector(@var{len}[,@var{list}])
\JP :: $BD9$5(B @var{len} $B$N%Y%/%H%k$r@8@.$9$k(B. 
\EG :: Creates a new vector object with its length @var{len}.
@item vect([@var{elements}])
\JP :: @var{elements} $B$rMWAG$H$9$k%Y%/%H%k$r@8@.$9$k(B.
\EG :: Creates a new vector object by @var{elements}.
@end table

@table @var
@item return
\JP $B%Y%/%H%k(B
\EG vector
@item len
\JP $B<+A3?t(B
\EG non-negative integer
@item list
\JP $B%j%9%H(B
\EG list
@item elements
\JP $BMWAG$NJB$S(B
\EG elements of the vector
@end table

@itemize @bullet
\BJP
@item
@code{vect} $B$OMWAG$NJB$S$+$i%Y%/%H%k$r@8@.$9$k(B.
@item
@code{vector} $B$O(B @code{newvect} $B$NJLL>$G$"$k(B.
@item
@code{newvect} $B$OD9$5(B @var{len} $B$N%Y%/%H%k$r@8@.$9$k(B. $BBh(B 2 $B0z?t$,$J$$>l9g(B, 
$B3F@.J,$O(B 0 $B$K=i4|2=$5$l$k(B. $BBh(B 2 $B0z?t$,$"$k>l9g(B, 
$B%$%s%G%C%/%9$N>.$5$$@.J,$+$i(B, $B%j%9%H$N(B
$B3FMWAG$K$h$j=i4|2=$5$l$k(B. $B3FMWAG$O(B, $B@hF,$+$i=g$K(B
$B;H$o$l(B, $BB-$j$J$$J,$O(B 0 $B$,Kd$a$i$l$k(B. 
@item
$B%Y%/%H%k$N@.J,$O(B, $BBh(B 0 $B@.J,$+$iBh(B @var{len}-1 $B@.J,$H$J$k(B. 
($BBh(B 1 $B@.J,$+$i$G$O$J$$;v$KCm0U(B. )
@item
$B%j%9%H$O3F@.J,$,(B, $B%]%$%s%?$rC)$k;v$K$h$C$F%7!<%1%s%7%c%k$K(B
$B8F$S=P$5$l$k$N$KBP$7(B, $B%Y%/%H%k$O3F@.J,$,(B
$BBh0l@.J,$+$i$N%a%b%j>e$N(B displacement ($BJQ0L(B)$B$K$h$C$F%i%s%@%`%"%/%;%9$G(B
$B8F$S=P$5$l(B, $B$=$N7k2L(B, $B@.J,$N%"%/%;%9;~4V$KBg$-$J:9$,=P$F$/$k(B. 
$B@.J,%"%/%;%9$O(B, $B%j%9%H$G$O(B, $B@.J,$NNL$,A}$($k$K=>$C$F(B
$B;~4V$,$+$+$k$h$&$K$J$k$,(B, $B%Y%/%H%k$G$O(B, $B@.J,$NNL$K0MB8$;$:$[$\0lDj$G$"$k(B. 
@item
@b{Asir} $B$G$O(B, $B=D%Y%/%H%k(B, $B2#%Y%/%H%k$N6hJL$O$J$$(B. 
$B9TNs$r:8$+$i3]$1$l$P=D%Y%/%H%k$H$_$J$5$l$k$7(B, $B1&$+$i3]$1$l$P2#%Y%/%H%k$H(B
$B$_$J$5$l$k(B. 
@item
$B%Y%/%H%k$ND9$5$O(B @code{size()} $B$K$h$C$FF@$i$l$k(B. 
@item
$BH!?t$N0z?t$H$7$F%Y%/%H%k$rEO$7$?>l9g(B, $BEO$5$l$?H!?t$O(B, $B$=$N%Y%/%H%k$N@.J,(B
$B$r=q$-49$($k$3$H$,$G$-$k(B. 
\E
\BEG
@item
@code{vect} creates a new vector object by its elements.
@item
@code{vector} is an alias of @code{newvect}.
@item 
@code{newvect} creates a new vector object with its length @var{len} and its elements
all cleared to value 0.
If the second argument, a list, is given, the vector is initialized by
the list elements.
Elements are used from the first through the last.
If the list is short for initializing the full vector,
0's are filled in the remaining vector elements.
@item 
Elements are indexed from 0 through @var{len}-1.  Note that the first
element has not index 1.
@item 
List and vector are different types in @b{Asir}.
Lists are conveniently used for representing many data objects whose
size varies dynamically as computation proceeds.
By its flexible expressive power, it is also conveniently used to
describe initial values for other structured objects as you see
for vectors.
Access for an element of a list is performed by following pointers to
next elements.  By this, access costs for list elements differ for
each element.
In contrast to lists, vector elements can be accessed in a same time,
because they are accessed by computing displacements from the top memory
location of the vector object.
      
Note also, in @b{Asir}, modification of an element of a vector causes
modification of the whole vector itself,
while modification of a list element does not cause the modification
of the whole list object.
      
By this, in @b{Asir} language,
a vector element designator can be a left value of
assignment statement, but a list element designator can NOT be a left
value of assignment statement.
      
@item
No distinction of column vectors and row vectors in @b{Asir}.
If a matrix is applied to a vector from left, the vector shall be taken
as a column vector, and if from right it shall be taken as a row vector.
@item
The length (or size or dimension) of a vector is given by function
@code{size()}.
@item 
When a vector is passed to a function as its argument
(actual parameter), the vector element can be modified in that
function.
      
@item
A vector is displayed in a similar format as for a list.
Note, however, there is a distinction: Elements of a vector are
separated simply by a `blank space', while those of a list by a `comma.'
\E
@end itemize

@example
[0] A=newvect(5);
[ 0 0 0 0 0 ]
[1] A=newvect(5,[1,2,3,4,[5,6]]);
[ 1 2 3 4 [5,6] ]
[2] A[0];
1
[3] A[4];
[5,6]
[4] size(A);
[5]
[5] length(A);
5
[6] vect(1,2,3,4,[5,6]);
[ 1 2 3 4 [5,6] ]
[7] def afo(V) @{ V[0] = x; @}
[8] afo(A)$
[9] A;
[ x 2 3 4 [5,6] ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newmat matrix}, @fref{size}, @fref{ltov}, @fref{vtol}.
@end table

\JP @node ltov,,, $BG[Ns(B
\EG @node ltov,,, Arrays
@subsection @code{ltov}
@findex ltov

@table @t
@item ltov(@var{list})
\JP :: $B%j%9%H$r%Y%/%H%k$KJQ49$9$k(B. 
\EG :: Converts a list into a vector.
@end table

@table @var
@item return
\JP $B%Y%/%H%k(B
\EG vector
@item list
\JP $B%j%9%H(B
\EG list
@end table

@itemize @bullet
\BJP
@item
$B%j%9%H(B @var{list} $B$rF1$8D9$5$N%Y%/%H%k$KJQ49$9$k(B. 
@item
$B$3$N4X?t$O(B @code{newvect(length(@var{list}), @var{list})} $B$KEy$7$$(B.
\E
\BEG
@item 
Converts a list @var{list} into a vector of same length.
See also @code{newvect()}.
\E
@end itemize

@example
[3] A=[1,2,3];
[4] ltov(A);
[ 1 2 3 ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newvect vector vect}, @fref{vtol}.
@end table

\JP @node vtol,,, $BG[Ns(B
\EG @node vtol,,, Arrays
@subsection @code{vtol}
@findex vtol

@table @t
@item vtol(@var{vect})
\JP :: $B%Y%/%H%k$r%j%9%H$KJQ49$9$k(B. 
\EG :: Converts a vector into a list.
@end table

@table @var
@item return
\JP $B%j%9%H(B
\EG list
@item vect
\JP $B%Y%/%H%k(B
\EG vector
@end table

@itemize @bullet
\BJP
@item
$BD9$5(B @var{n} $B$N%Y%/%H%k(B @var{vect} $B$r(B
 @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]} $B$J$k%j%9%H$KJQ49$9$k(B. 
@item
$B%j%9%H$+$i%Y%/%H%k$X$NJQ49$O(B @code{newvect()} $B$G9T$&(B. 
\E
\BEG
@item 
Converts a vector @var{vect} of length @var{n} into
a list @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]}.
@item 
A conversion from a list to a vector is done by @code{newvect()}.
\E
@end itemize

@example
[3] A=newvect(3,[1,2,3]);
[ 1 2 3 ]
[4] vtol(A);
[1,2,3]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newvect vector vect}, @fref{ltov}.
@end table

\JP @node newbytearray,,, $BG[Ns(B
\EG @node newbytearray,,, Arrays
@subsection @code{newbytearray}
@findex newbytearray

@table @t
@item newbytearray(@var{len},[@var{listorstring}])
\JP :: $BD9$5(B @var{len} $B$N(B byte array $B$r@8@.$9$k(B.
\EG :: Creates a new byte array.
@end table

@table @var
@item return
byte array
@item len
\JP $B<+A3?t(B
\EG non-negative integer
@item listorstring
\JP $B%j%9%H$^$?$OJ8;zNs(B
\EG list or string
@end table

@itemize @bullet
@item
\JP @code{newvect} $B$HF1MM$K$7$F(B byte array $B$r@8@.$9$k(B.
\EG This function generates a byte array. The specification is
similar to that of @code{newvect}.
@item
\JP $BJ8;zNs$G=i4|CM$r;XDj$9$k$3$H$b2DG=$G$"$k(B.
\EG The initial value can be specified by a character string.
@item
\JP byte array $B$NMWAG$N%"%/%;%9$OG[Ns$HF1MM$G$"$k(B.
\EG One can access elements of a byte array just as an array.
@end itemize

@example
[182] A=newbytearray(3);
|00 00 00|
[183] A=newbytearray(3,[1,2,3]);
|01 02 03|
[184] A=newbytearray(3,"abc");  
|61 62 63|
[185] A[0];
97
[186] A[1]=123;
123
[187] A;
|61 7b 63|
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newvect vector vect}.
@end table

\JP @node newmat matrix,,, $BG[Ns(B
\EG @node newmat matrix,,, Arrays
@subsection @code{newmat}, @code{matrix}
@findex newmat
@findex matrix

@table @t
@item newmat(@var{row},@var{col} [,[[@var{a},@var{b},...],[@var{c},@var{d},...],...]])
@item matrix(@var{row},@var{col} [,[[@var{a},@var{b},...],[@var{c},@var{d},...],...]])
\JP :: @var{row} $B9T(B @var{col} $BNs$N9TNs$r@8@.$9$k(B. 
\EG :: Creates a new matrix with @var{row} rows and @var{col} columns.
@end table

@table @var
@item return
\JP $B9TNs(B
\EG matrix
@item row col
\JP $B<+A3?t(B
\EG non-negative integer
@item a b c d
\JP $BG$0U(B
\EG arbitrary
@end table

@itemize @bullet
\BJP
@item
@code{matrix} $B$O(B @code{newmat} $B$NJLL>$G$"$k(B.
@item
@var{row} $B9T(B @var{col} $BNs$N9TNs$r@8@.$9$k(B. $BBh(B 3 $B0z?t$,$J$$>l9g(B, 
$B3F@.J,$O(B 0 $B$K=i4|2=$5$l$k(B. $BBh(B 3 $B0z?t$,$"$k>l9g(B, 
$B%$%s%G%C%/%9$N>.$5$$@.J,$+$i(B, $B3F9T$,(B, $B%j%9%H$N(B
$B3FMWAG(B ($B$3$l$O$^$?%j%9%H$G$"$k(B) $B$K$h$j=i4|2=$5$l$k(B. $B3FMWAG$O(B, $B@hF,$+$i=g$K(B
$B;H$o$l(B, $BB-$j$J$$J,$O(B 0 $B$,Kd$a$i$l$k(B. 
@item
$B9TNs$N%5%$%:$O(B @code{size()} $B$GF@$i$l$k(B. 
@item
@code{M} $B$,9TNs$N$H$-(B, @code{M[I]} $B$K$h$jBh(B @code{I} $B9T$r%Y%/%H%k$H$7$F(B
$B<h$j=P$9$3$H$,$G$-$k(B. $B$3$N%Y%/%H%k$O(B, $B$b$H$N9TNs$H@.J,$r6&M-$7$F$*$j(B, 
$B$$$:$l$+$N@.J,$r=q$-49$($l$P(B, $BB>$NBP1~$9$k@.J,$b=q$-49$o$k$3$H$K$J$k(B. 
@item
$BH!?t$N0z?t$H$7$F9TNs$rEO$7$?>l9g(B, $BEO$5$l$?H!?t$O(B, $B$=$N9TNs$N@.J,(B
$B$r=q$-49$($k$3$H$,$G$-$k(B. 
\E
\BEG
@item
@code{matrix} is an alias of @code{newmat}.
@item 
If the third argument, a list, is given, the newly created matrix
is initialized so that each element of the list (again a list)
initializes each of the rows of the matrix.
Elements are used from the first through the last.
If the list is short, 0's are filled in the remaining matrix elements.
If no third argument is given all the elements are cleared to 0.
@item 
The size of a matrix is given by function  @code{size()}.
@item 
Let @code{M} be a program variable assigned to a matrix.
Then, @code{M[I]} denotes a (row) vector which corresponds with
the @code{I}-th row of the matrix.
Note that the vector shares its element with the original matrix.
Subsequently, if an element of the vector is modified, then the
corresponding matrix element is also modified.
@item 
When a matrix is passed to a function as its argument
(actual parameter), the matrix element can be modified within that
function.
\E
@end itemize

@example
[0] A = newmat(3,3,[[1,1,1],[x,y],[x^2]]);
[ 1 1 1 ]
[ x y 0 ]
[ x^2 0 0 ]
[1] det(A);
-y*x^2
[2] size(A);
[3,3]
[3] A[1];
[ x y 0 ]
[4] A[1][3];
getarray : Out of range
return to toplevel
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newvect vector vect}, @fref{size}, @fref{det nd_det invmat}.
@end table

\JP @node mat matr matc,,, $BG[Ns(B
\EG @node mat matr matc,,, Arrays
@subsection @code{mat}, @code{matr}, @code{matc}
@findex mat
@findex matr
@findex matc

@table @t
@item mat(@var{vector}[,...])
@item matr(@var{vector}[,...])
\JP :: $B9T%Y%/%H%k$NJB$S$+$i9TNs$r@8@.$9$k(B. 
\EG :: Creates a new matrix by list of row vectors.
@item matc(@var{vector}[,...])
\JP :: $BNs%Y%/%H%k$NJB$S$+$i9TNs$r@8@.$9$k(B. 
\EG :: Creates a new matrix by list of column vectors.
@end table

@table @var
@item return
\JP $B9TNs(B
\EG matrix
@item @var{vector}
\JP $BG[Ns$^$?$O%j%9%H(B
\EG array or list
@end table

@itemize @bullet
\BJP
@item
@code{mat} $B$O(B @code{matr} $B$NJLL>$G$"$k(B.
@item
$B0z?t$N3F%Y%/%H%k$OF1$8D9$5$r$b$D(B.
$B3FMWAG$O(B, $B@hF,$+$i=g$K;H$o$l(B, $BB-$j$J$$J,$O(B 0 $B$,Kd$a$i$l$k(B. 
\E
\BEG
@item
@code{mat} is an alias of @code{matr}.
@item 
Each vector has same length.
Elements are used from the first through the last.
If the list is short, 0's are filled in the remaining matrix elements.
\E
@end itemize

@example
[0] matr([1,2,3],[4,5,6],[7,8]);
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 0 ]
[1] matc([1,2,3],[4,5,6],[7,8]);
[ 1 4 7 ]
[ 2 5 8 ]
[ 3 6 0 ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newmat matrix}
@end table

\JP @node size,,, $BG[Ns(B
\EG @node size,,, Arrays
@subsection @code{size}
@findex size

@table @t
@item size(@var{vect|mat})
\JP :: @code{[@var{vect} $B$ND9$5(B]} $B$^$?$O(B @code{[@var{mat} $B$N9T?t(B,@var{mat} $B$NNs?t(B]}. 
\BEG
:: A list containing the number of elements of the given vector,
@code{[size of @var{vect}]},
or a list containing row size and column size of the given matrix,
@code{[row size of @var{mat}, column size of @var{mat}]}.
\E
@end table

@table @var
@item return
\JP $B%j%9%H(B
\EG list
@item vect
\JP $B%Y%/%H%k(B
\EG vector
@item mat
\JP $B9TNs(B
\EG matrix
@end table

@itemize @bullet
\BJP
@item
@var{vect} $B$ND9$5(B, $B$^$?$O(B @var{mat} $B$NBg$-$5$r%j%9%H$G=PNO$9$k(B. 
@item
@var{vect} $B$ND9$5$O(B @code{length()} $B$G5a$a$k$3$H$b$G$-$k(B.
@item
@var{list} $B$ND9$5$O(B @code{length()}$B$r(B, $BM-M}<0$K8=$l$kC19`<0$N?t$O(B @code{nmono()} $B$rMQ$$$k(B. 
\E
\BEG
@item 
Return a list consisting of the dimension of the vector @var{vect},
or a list consisting of the row size and column size of the matrix
@var{matrix}.
@item 
Use @code{length()} for the size of @var{list}, and
@code{nmono()} for the number of monomials with non-zero coefficients
in a rational expression.
\E
@end itemize

@example
[0] A = newvect(4);
[ 0 0 0 0 ]
[1] size(A);
[4]
[2] length(A);
4
[3] B = newmat(2,3,[[1,2,3],[4,5,6]]);
[ 1 2 3 ]
[ 4 5 6 ]
[4] size(B);
[2,3]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{car cdr cons append reverse length}, @fref{nmono}.
@end table

\JP @node det nd_det invmat,,, $BG[Ns(B
\EG @node det nd_det invmat,,, Arrays
@subsection @code{det}, @code{nd_det}, @code{invmat}
@findex det
@findex nd_det
@findex invmat

@table @t
@item det(@var{mat}[,@var{mod}])
@itemx nd_det(@var{mat}[,@var{mod}])
\JP :: @var{mat} $B$N9TNs<0$r5a$a$k(B. 
\EG :: Determinant of @var{mat}.
@item invmat(@var{mat})
\JP :: @var{mat} $B$N5U9TNs$r5a$a$k(B. 
\EG :: Inverse matrix of @var{mat}.
@end table

@table @var
@item return
\JP @code{det}: $B<0(B, @code{invmat}: $B%j%9%H(B
\EG @code{det}: expression, @code{invmat}: list
@item mat
\JP $B9TNs(B
\EG matrix
@item mod
\JP $BAG?t(B
\EG prime
@end table

@itemize @bullet
\BJP
@item
@code{det} $B$*$h$S(B @code{nd_det} $B$O9TNs(B @var{mat} $B$N9TNs<0$r5a$a$k(B. 
@code{invmat} $B$O9TNs(B @var{mat} $B$N5U9TNs$r5a$a$k(B. $B5U9TNs$O(B @code{[$BJ,;R(B, $BJ,Jl(B]}
$B$N7A$GJV$5$l(B, @code{$BJ,;R(B}$B$,9TNs(B, @code{$BJ,;R(B/$BJ,Jl(B} $B$,5U9TNs$H$J$k(B. 
@item
$B0z?t(B @var{mod} $B$,$"$k;~(B, GF(@var{mod}) $B>e$G$N9TNs<0$r5a$a$k(B. 
@item
$BJ,?t$J$7$N%,%&%9>C5nK!$K$h$C$F$$$k$?$a(B, $BB?JQ?tB?9`<0$r@.J,$H$9$k(B
$B9TNs$KBP$7$F$O>.9TNs<0E83+$K$h$kJ}K!$N$[$&$,8zN($,$h$$>l9g$b$"$k(B. 
@item
@code{nd_det} $B$OM-M}?t$^$?$OM-8BBN>e$NB?9`<09TNs$N9TNs<0(B
$B7W;;@lMQ$G$"$k(B. $B%"%k%4%j%:%`$O$d$O$jJ,?t$J$7$N%,%&%9>C5nK!$@$,(B,
$B%G!<%?9=B$$*$h$S>h=|;;$N9)IW$K$h$j(B, $B0lHL$K(B @code{det} $B$h$j9bB.$K(B
$B7W;;$G$-$k(B.
\E
\BEG
@item 
@code{det} and @code{nd_det} compute the determinant of matrix @var{mat}.
@code{invmat} computes the inverse matrix of matrix @var{mat}.
@code{invmat} returns a list @code{[num,den]}, where @code{num}
is a matrix and @code{num/den} represents the inverse matrix.
@item 
The computation is done over GF(@var{mod}) if @var{mod} is specitied.
@item 
The fraction free Gaussian algorithm is employed.  For matrices with
multi-variate polynomial entries, minor expansion algorithm sometimes
is more efficient than the fraction free Gaussian algorithm.
@item
@code{nd_det} can be used for computing the determinant of a matrix with
polynomial entries over the rationals or finite fields. The algorithm
is an improved vesion of the fraction free Gaussian algorithm
and it computes the determinant faster than @code{det}.
\E
@end itemize

@example
[91] A=newmat(5,5)$                         
[92] V=[x,y,z,u,v];
[x,y,z,u,v]
[93] for(I=0;I<5;I++)for(J=0,B=A[I],W=V[I];J<5;J++)B[J]=W^J;
[94] A;
[ 1 x x^2 x^3 x^4 ]
[ 1 y y^2 y^3 y^4 ]
[ 1 z z^2 z^3 z^4 ]
[ 1 u u^2 u^3 u^4 ]
[ 1 v v^2 v^3 v^4 ]
[95] fctr(det(A));
[[1,1],[u-v,1],[-z+v,1],[-z+u,1],[-y+u,1],[y-v,1],[-y+z,1],[-x+u,1],
[-x+z,1],[-x+v,1],[-x+y,1]]
[96] A = newmat(3,3)$
[97] for(I=0;I<3;I++)for(J=0,B=A[I],W=V[I];J<3;J++)B[J]=W^J;
[98] A;
[ 1 x x^2 ]
[ 1 y y^2 ]
[ 1 z z^2 ]
[99] invmat(A);
[[ -z*y^2+z^2*y z*x^2-z^2*x -y*x^2+y^2*x ]
[ y^2-z^2 -x^2+z^2 x^2-y^2 ]
[ -y+z x-z -x+y ],(-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y]
[100] A*B[0];
[ (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 0 ]
[ 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 ]
[ 0 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y ]
[101] map(red,A*B[0]/B[1]);
[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newmat matrix}.
@end table

\JP @node qsort,,, $BG[Ns(B
\EG @node qsort,,, Arrays
@subsection @code{qsort}
@findex qsort

@table @t
@item qsort(@var{array}[,@var{func}]) 
\JP :: $B0l<!85G[Ns(B @var{array} $B$r%=!<%H$9$k(B. 
\EG :: Sorts an array @var{array}.
@end table

@table @var
@item return
\JP @var{array} ($BF~NO$HF1$8(B; $BMWAG$N$_F~$lBX$o$k(B)
\EG @var{array} (The same as the input; Only the elements are exchanged.)
@item array
\JP $B0l<!85G[Ns(B
\EG array
@item func
\JP $BHf3SMQ4X?t(B
\EG function for comparison
@end table

@itemize @bullet
\BJP
@item
$B0l<!85G[Ns$r(B quick sort $B$G%=!<%H$9$k(B. 
@item
$BHf3SMQ4X?t$,;XDj$5$l$F$$$J$$>l9g(B, $B%*%V%8%'%/%H$I$&$7$NHf3S7k2L$G(B
$B=g=x$,2<$N$b$N$+$i=g$KJB$Y49$($i$l$k(B. 
@item
0, 1, -1 $B$rJV$9(B 2 $B0z?t4X?t$,(B @var{func} $B$H$7$FM?$($i$l$?>l9g(B, 
@code{@var{func}(A,B)=1} $B$N>l9g$K(B @code{A<B} $B$H$7$F(B, $B=g=x$,2<$N(B
$B$b$N$+$i=g$KJB$Y49$($i$l$k(B. 
@item
$BG[Ns$O?7$?$K@8@.$5$l$:(B, $B0z?t$NG[Ns$NMWAG$N$_F~$lBX$o$k(B. 
\E
\BEG
@item
This function sorts an array by @var{quick sort}.
@item
If @var{func} is not specified, the built-in comparison function
is used and the array is sorted in increasing order.
@item
If a function of two arguments @var{func} which returns 0, 1, or -1
is provided, then an ordering is detemined so that
@code{A<B} if @code{@var{func}(A,B)=1} holds, and
the array is sorted in increasing order with respect to the ordering.
@item
The returned array is the same as the input. Only the elements
are exchanged.
\E
@end itemize

@example
[0] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]));
[ -1 0 1 2 3 4 6 6 7 9 ]
[1] def rev(A,B) @{ return A>B?-1:(A<B?1:0); @}
[2] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]),rev);
[ 9 7 6 6 4 3 2 1 0 -1 ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{ord}, @fref{vars}.
@end table

\JP @node rowx rowm rowa colx colm cola,,, $BG[Ns(B
\EG @node rowx rowm rowa colx colm cola,,, Arrays
@subsection @code{rowx}, @code{rowm}, @code{rowa}, @code{colx}, @code{colm}, @code{cola}
@findex rowx
@findex rowm
@findex rowa
@findex colx
@findex colm
@findex cola

@table @t
@item rowx(@var{matrix},@var{i},@var{j})
\JP :: $BBh(B @var{i} $B9T$HBh(B @var{j} $B9T$r8r49$9$k(B.
\EG :: Exchanges the @var{i}-th and @var{j}-th rows.
@item rowm(@var{matrix},@var{i},@var{c})
\JP :: $BBh(B @var{i} $B9T$r(B @var{c} $BG\$9$k(B.
\EG :: Multiplies the @var{i}-th row by @var{c}.
@item rowa(@var{matrix},@var{i},@var{c})
\JP :: $BBh(B @var{i} $B9T$KBh(B @var{i} $B9T$N(B @var{c} $BG\$r2C$($k(B.
\EG :: Appends @var{c} times the @var{j}-th row to the @var{j}-th row.
@item colx(@var{matrix},@var{i},@var{j})
\JP :: $BBh(B @var{i} $B9T$HBh(B @var{j} $B9T$r8r49$9$k(B.
\EG :: Exchanges the @var{i}-th and @var{j}-th columns.
@item colm(@var{matrix},@var{i},@var{c})
\JP :: $BBh(B @var{i} $B9T$r(B @var{c} $BG\$9$k(B.
\EG :: Multiplies the @var{i}-th column by @var{c}.
@item cola(@var{matrix},@var{i},@var{c})
\JP :: $BBh(B @var{i} $B9T$KBh(B @var{i} $B9T$N(B @var{c} $BG\$r2C$($k(B.
\EG :: Appends @var{c} times the @var{j}-th column to the @var{j}-th column.
@end table

@table @var
@item return
\JP $B9TNs(B
\EG matrix
@item @var{i}, @var{j}
\JP $B@0?t(B
\EG integers
@item @var{c}
\JP $B78?t(B
\EG coefficient
@end table

@itemize @bullet
\BJP
@item
$B9TNs$N4pK\JQ7A$r9T$&$?$a$N4X?t$G$"$k(B.
@item
$B9TNs$,GK2u$5$l$k$3$H$KCm0U$9$k(B.
\E
\BEG
@item
These operations are destructive for the matrix.
\E
@end itemize

@example
[0] A=newmat(3,3,[[1,2,3],[4,5,6],[7,8,9]]);
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]
[1] rowx(A,1,2)$
[2] A;
[ 1 2 3 ]
[ 7 8 9 ]
[ 4 5 6 ]
[3] rowm(A,2,x);
[ 1 2 3 ]
[ 7 8 9 ]
[ 4*x 5*x 6*x ]
[4] rowa(A,0,1,z);
[ 7*z+1 8*z+2 9*z+3 ]
[ 7 8 9 ]
[ 4*x 5*x 6*x ]
@end example

@table @t
\JP @item $B;2>H(B
\EG @item References
@fref{newmat matrix}
@end table