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

Annotation of OpenXM/src/asir-doc/parts/builtin/array.texi, Revision 1.8

1.8     ! takayama    1: @comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/array.texi,v 1.7 2003/04/20 08:01:28 noro Exp $
1.2       noro        2: \BJP
1.1       noro        3: @node $BG[Ns(B,,, $BAH$_9~$_H!?t(B
                      4: @section $BG[Ns(B
1.2       noro        5: \E
                      6: \BEG
                      7: @node Arrays,,, Built-in Function
                      8: @section Arrays
                      9: \E
1.1       noro       10:
                     11: @menu
                     12: * newvect::
1.4       noro       13: * newbytearray::
1.1       noro       14: * vtol::
                     15: * newmat::
                     16: * size::
1.5       noro       17: * det invmat::
1.1       noro       18: * qsort::
                     19: @end menu
                     20:
1.2       noro       21: \JP @node newvect,,, $BG[Ns(B
                     22: \EG @node newvect,,, Arrays
1.1       noro       23: @subsection @code{newvect}
                     24: @findex newvect
                     25:
                     26: @table @t
                     27: @item newvect(@var{len}[,@var{list}])
1.2       noro       28: \JP :: $BD9$5(B @var{len} $B$N%Y%/%H%k$r@8@.$9$k(B.
                     29: \EG :: Creates a new vector object with its length @var{len}.
1.1       noro       30: @end table
                     31:
                     32: @table @var
                     33: @item return
1.2       noro       34: \JP $B%Y%/%H%k(B
                     35: \EG vector
1.1       noro       36: @item len
1.2       noro       37: \JP $B<+A3?t(B
                     38: \EG non-negative integer
1.1       noro       39: @item list
1.2       noro       40: \JP $B%j%9%H(B
                     41: \EG list
1.1       noro       42: @end table
                     43:
                     44: @itemize @bullet
1.2       noro       45: \BJP
1.1       noro       46: @item
                     47: $BD9$5(B @var{len} $B$N%Y%/%H%k$r@8@.$9$k(B. $BBh(B 2 $B0z?t$,$J$$>l9g(B,
                     48: $B3F@.J,$O(B 0 $B$K=i4|2=$5$l$k(B. $BBh(B 2 $B0z?t$,$"$k>l9g(B,
                     49: $B%$%s%G%C%/%9$N>.$5$$@.J,$+$i(B, $B%j%9%H$N(B
                     50: $B3FMWAG$K$h$j=i4|2=$5$l$k(B. $B3FMWAG$O(B, $B@hF,$+$i=g$K(B
                     51: $B;H$o$l(B, $BB-$j$J$$J,$O(B 0 $B$,Kd$a$i$l$k(B.
                     52: @item
                     53: $B%Y%/%H%k$N@.J,$O(B, $BBh(B 0 $B@.J,$+$iBh(B @var{len}-1 $B@.J,$H$J$k(B.
                     54: ($BBh(B 1 $B@.J,$+$i$G$O$J$$;v$KCm0U(B. )
                     55: @item
                     56: $B%j%9%H$O3F@.J,$,(B, $B%]%$%s%?$rC)$k;v$K$h$C$F%7!<%1%s%7%c%k$K(B
                     57: $B8F$S=P$5$l$k$N$KBP$7(B, $B%Y%/%H%k$O3F@.J,$,(B
                     58: $BBh0l@.J,$+$i$N%a%b%j>e$N(B displacement ($BJQ0L(B)$B$K$h$C$F%i%s%@%`%"%/%;%9$G(B
                     59: $B8F$S=P$5$l(B, $B$=$N7k2L(B, $B@.J,$N%"%/%;%9;~4V$KBg$-$J:9$,=P$F$/$k(B.
                     60: $B@.J,%"%/%;%9$O(B, $B%j%9%H$G$O(B, $B@.J,$NNL$,A}$($k$K=>$C$F(B
                     61: $B;~4V$,$+$+$k$h$&$K$J$k$,(B, $B%Y%/%H%k$G$O(B, $B@.J,$NNL$K0MB8$;$:$[$\0lDj$G$"$k(B.
                     62: @item
                     63: @b{Asir} $B$G$O(B, $B=D%Y%/%H%k(B, $B2#%Y%/%H%k$N6hJL$O$J$$(B.
                     64: $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
                     65: $B$_$J$5$l$k(B.
                     66: @item
                     67: $B%Y%/%H%k$ND9$5$O(B @code{size()} $B$K$h$C$FF@$i$l$k(B.
                     68: @item
                     69: $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
                     70: $B$r=q$-49$($k$3$H$,$G$-$k(B.
1.2       noro       71: \E
                     72: \BEG
                     73: @item
                     74: Creates a new vector object with its length @var{len} and its elements
                     75: all cleared to value 0.
                     76: If the second argument, a list, is given, the vector is initialized by
                     77: the list elements.
                     78: Elements are used from the first through the last.
                     79: If the list is short for initializing the full vector,
                     80: 0's are filled in the remaining vector elements.
                     81: @item
                     82: Elements are indexed from 0 through @var{len}-1.  Note that the first
                     83: element has not index 1.
                     84: @item
                     85: List and vector are different types in @b{Asir}.
                     86: Lists are conveniently used for representing many data objects whose
                     87: size varies dynamically as computation proceeds.
                     88: By its flexible expressive power, it is also conveniently used to
                     89: describe initial values for other structured objects as you see
                     90: for vectors.
                     91: Access for an element of a list is performed by following pointers to
                     92: next elements.  By this, access costs for list elements differ for
                     93: each element.
                     94: In contrast to lists, vector elements can be accessed in a same time,
                     95: because they are accessed by computing displacements from the top memory
                     96: location of the vector object.
                     97:
                     98: Note also, in @b{Asir}, modification of an element of a vector causes
                     99: modification of the whole vector itself,
                    100: while modification of a list element does not cause the modification
                    101: of the whole list object.
                    102:
                    103: By this, in @b{Asir} language,
                    104: a vector element designator can be a left value of
                    105: assignment statement, but a list element designator can NOT be a left
                    106: value of assignment statement.
                    107:
                    108: @item
                    109: No distinction of column vectors and row vectors in @b{Asir}.
                    110: If a matrix is applied to a vector from left, the vector shall be taken
                    111: as a column vector, and if from right it shall be taken as a row vector.
                    112: @item
                    113: The length (or size or dimension) of a vector is given by function
                    114: @code{size()}.
                    115: @item
                    116: When a vector is passed to a function as its argument
                    117: (actual parameter), the vector element can be modified in that
                    118: function.
                    119:
                    120: @item
                    121: A vector is displayed in a similar format as for a list.
                    122: Note, however, there is a distinction: Elements of a vector are
                    123: separated simply by a `blank space', while those of a list by a `comma.'
                    124: \E
1.1       noro      125: @end itemize
                    126:
                    127: @example
                    128: [0] A=newvect(5);
                    129: [ 0 0 0 0 0 ]
                    130: [1] A=newvect(5,[1,2,3,4,[5,6]]);
                    131: [ 1 2 3 4 [5,6] ]
                    132: [2] A[0];
                    133: 1
                    134: [3] A[4];
                    135: [5,6]
                    136: [4] size(A);
                    137: [5]
                    138: [5] def afo(V) @{ V[0] = x; @}
                    139: [6] afo(A)$
                    140: [7] A;
                    141: [ x 2 3 4 [5,6] ]
                    142: @end example
                    143:
                    144: @table @t
1.2       noro      145: \JP @item $B;2>H(B
                    146: \EG @item References
1.3       takayama  147: @fref{newmat}, @fref{size}, @fref{vtol}.
1.1       noro      148: @end table
                    149:
1.2       noro      150: \JP @node vtol,,, $BG[Ns(B
                    151: \EG @node vtol,,, Arrays
1.1       noro      152: @subsection @code{vtol}
                    153: @findex vtol
                    154:
                    155: @table @t
                    156: @item vtol(@var{vect})
1.2       noro      157: \JP :: $B%Y%/%H%k$r%j%9%H$KJQ49$9$k(B.
                    158: \EG :: Converts a vector into a list.
1.1       noro      159: @end table
                    160:
                    161: @table @var
                    162: @item return
1.2       noro      163: \JP $B%j%9%H(B
                    164: \EG list
1.1       noro      165: @item vect
1.2       noro      166: \JP $B%Y%/%H%k(B
                    167: \EG vector
1.1       noro      168: @end table
                    169:
                    170: @itemize @bullet
1.2       noro      171: \BJP
1.1       noro      172: @item
                    173: $BD9$5(B @var{n} $B$N%Y%/%H%k(B @var{vect} $B$r(B
                    174:  @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]} $B$J$k%j%9%H$KJQ49$9$k(B.
                    175: @item
                    176: $B%j%9%H$+$i%Y%/%H%k$X$NJQ49$O(B @code{newvect()} $B$G9T$&(B.
1.2       noro      177: \E
                    178: \BEG
                    179: @item
                    180: Converts a vector @var{vect} of length @var{n} into
                    181: a list @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]}.
                    182: @item
                    183: A conversion from a list to a vector is done by @code{newvect()}.
                    184: \E
1.1       noro      185: @end itemize
                    186:
                    187: @example
                    188: [3] A=newvect(3,[1,2,3]);
                    189: [ 1 2 3 ]
                    190: [4] vtol(A);
                    191: [1,2,3]
1.4       noro      192: @end example
                    193:
                    194: @table @t
                    195: \JP @item $B;2>H(B
                    196: \EG @item References
                    197: @fref{newvect}.
                    198: @end table
                    199:
                    200: \JP @node newbytearray,,, $BG[Ns(B
                    201: \EG @node newbytearray,,, Arrays
                    202: @subsection @code{newbytearray}
                    203: @findex newbytearray
                    204:
                    205: @table @t
                    206: @item newbytearray(@var{len},[@var{listorstring}])
                    207: \JP :: $BD9$5(B @var{len} $B$N(B byte array $B$r@8@.$9$k(B.
                    208: \EG :: Creates a new byte array.
                    209: @end table
                    210:
                    211: @table @var
                    212: @item return
                    213: byte array
                    214: @item len
                    215: \JP $B<+A3?t(B
                    216: \EG non-negative integer
                    217: @item listorstring
                    218: \JP $B%j%9%H$^$?$OJ8;zNs(B
                    219: \EG list or string
                    220: @end table
                    221:
                    222: @itemize @bullet
                    223: @item
                    224: \JP @code{newvect} $B$HF1MM$K$7$F(B byte array $B$r@8@.$9$k(B.
                    225: \EG This function generates a byte array. The specification is
                    226: similar to that of @code{newvect}.
                    227: @item
                    228: \JP $BJ8;zNs$G=i4|CM$r;XDj$9$k$3$H$b2DG=$G$"$k(B.
                    229: \EG The initial value can be specified by a character string.
                    230: @item
                    231: \JP byte array $B$NMWAG$N%"%/%;%9$OG[Ns$HF1MM$G$"$k(B.
                    232: \EG One can access elements of a byte array just as an array.
                    233: @end itemize
                    234:
                    235: @example
                    236: [182] A=newbytearray(3);
                    237: |00 00 00|
                    238: [183] A=newbytearray(3,[1,2,3]);
                    239: |01 02 03|
                    240: [184] A=newbytearray(3,"abc");
                    241: |61 62 63|
                    242: [185] A[0];
                    243: 97
                    244: [186] A[1]=123;
                    245: 123
                    246: [187] A;
                    247: |61 7b 63|
1.1       noro      248: @end example
                    249:
                    250: @table @t
1.2       noro      251: \JP @item $B;2>H(B
                    252: \EG @item References
1.1       noro      253: @fref{newvect}.
                    254: @end table
                    255:
1.2       noro      256: \JP @node newmat,,, $BG[Ns(B
                    257: \EG @node newmat,,, Arrays
1.1       noro      258: @subsection @code{newmat}
                    259: @findex newmat
                    260:
                    261: @table @t
1.6       noro      262: @item newmat(@var{row},@var{col} [,[[@var{a},@var{b},...],[@var{c},@var{d},...],...]])
1.2       noro      263: \JP :: @var{row} $B9T(B @var{col} $BNs$N9TNs$r@8@.$9$k(B.
                    264: \EG :: Creates a new matrix with @var{row} rows and @var{col} columns.
1.1       noro      265: @end table
                    266:
                    267: @table @var
                    268: @item return
1.2       noro      269: \JP $B9TNs(B
                    270: \EG matrix
1.6       noro      271: @item row col
1.2       noro      272: \JP $B<+A3?t(B
                    273: \EG non-negative integer
1.6       noro      274: @item a b c d
1.2       noro      275: \JP $BG$0U(B
                    276: \EG arbitrary
1.1       noro      277: @end table
                    278:
                    279: @itemize @bullet
1.2       noro      280: \BJP
1.1       noro      281: @item
                    282: @var{row} $B9T(B @var{col} $BNs$N9TNs$r@8@.$9$k(B. $BBh(B 3 $B0z?t$,$J$$>l9g(B,
                    283: $B3F@.J,$O(B 0 $B$K=i4|2=$5$l$k(B. $BBh(B 3 $B0z?t$,$"$k>l9g(B,
                    284: $B%$%s%G%C%/%9$N>.$5$$@.J,$+$i(B, $B3F9T$,(B, $B%j%9%H$N(B
                    285: $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
                    286: $B;H$o$l(B, $BB-$j$J$$J,$O(B 0 $B$,Kd$a$i$l$k(B.
                    287: @item
                    288: $B9TNs$N%5%$%:$O(B @code{size()} $B$GF@$i$l$k(B.
                    289: @item
                    290: @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
                    291: $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,
                    292: $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.
                    293: @item
                    294: $BH!?t$N0z?t$H$7$F9TNs$rEO$7$?>l9g(B, $BEO$5$l$?H!?t$O(B, $B$=$N9TNs$N@.J,(B
                    295: $B$r=q$-49$($k$3$H$,$G$-$k(B.
1.2       noro      296: \E
                    297: \BEG
                    298: @item
                    299: If the third argument, a list, is given, the newly created matrix
                    300: is initialized so that each element of the list (again a list)
                    301: initializes each of the rows of the matrix.
                    302: Elements are used from the first through the last.
                    303: If the list is short, 0's are filled in the remaining matrix elements.
                    304: If no third argument is given all the elements are cleared to 0.
                    305: @item
                    306: The size of a matrix is given by function  @code{size()}.
                    307: @item
                    308: Let @code{M} be a program variable assigned to a matrix.
                    309: Then, @code{M[I]} denotes a (row) vector which corresponds with
                    310: the @code{I}-th row of the matrix.
                    311: Note that the vector shares its element with the original matrix.
                    312: Subsequently, if an element of the vector is modified, then the
                    313: corresponding matrix element is also modified.
                    314: @item
                    315: When a matrix is passed to a function as its argument
                    316: (actual parameter), the matrix element can be modified within that
                    317: function.
                    318: \E
1.1       noro      319: @end itemize
                    320:
                    321: @example
                    322: [0] A = newmat(3,3,[[1,1,1],[x,y],[x^2]]);
                    323: [ 1 1 1 ]
                    324: [ x y 0 ]
                    325: [ x^2 0 0 ]
                    326: [1] det(A);
                    327: -y*x^2
                    328: [2] size(A);
                    329: [3,3]
                    330: [3] A[1];
                    331: [ x y 0 ]
                    332: [4] A[1][3];
                    333: getarray : Out of range
                    334: return to toplevel
                    335: @end example
                    336:
                    337: @table @t
1.2       noro      338: \JP @item $B;2>H(B
                    339: \EG @item References
1.5       noro      340: @fref{newvect}, @fref{size}, @fref{det invmat}.
1.1       noro      341: @end table
                    342:
1.2       noro      343: \JP @node size,,, $BG[Ns(B
                    344: \EG @node size,,, Arrays
1.1       noro      345: @subsection @code{size}
                    346: @findex size
                    347:
                    348: @table @t
                    349: @item size(@var{vect|mat})
1.2       noro      350: \JP :: @code{[@var{vect} $B$ND9$5(B]} $B$^$?$O(B @code{[@var{mat} $B$N9T?t(B,@var{mat} $B$NNs?t(B]}.
                    351: \BEG
                    352: :: A list containing the number of elements of the given vector,
                    353: @code{[size of @var{vect}]},
                    354: or a list containing row size and column size of the given matrix,
                    355: @code{[row size of @var{mat}, column size of @var{mat}]}.
                    356: \E
1.1       noro      357: @end table
                    358:
                    359: @table @var
                    360: @item return
1.2       noro      361: \JP $B%j%9%H(B
                    362: \EG list
1.1       noro      363: @item vect
1.2       noro      364: \JP $B%Y%/%H%k(B
                    365: \EG vector
1.1       noro      366: @item mat
1.2       noro      367: \JP $B9TNs(B
                    368: \EG matrix
1.1       noro      369: @end table
                    370:
                    371: @itemize @bullet
1.2       noro      372: \BJP
1.1       noro      373: @item
                    374: @var{vect} $BKt$O(B, @var{mat} $B$N%5%$%:$r%j%9%H$G=PNO$9$k(B.
                    375: @item
                    376: @var{list} $B$N%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.
1.2       noro      377: \E
                    378: \BEG
                    379: @item
                    380: Return a list consisting of the dimension of the vector @var{vect},
                    381: or a list consisting of the row size and column size of the matrix
                    382: @var{matrix}.
                    383: @item
                    384: Use @code{length()} for the size of @var{list}, and
                    385: @code{nmono()} for the number of monomials with non-zero coefficients
                    386: in a rational expression.
                    387: \E
1.1       noro      388: @end itemize
                    389:
                    390: @example
                    391: [0] A = newvect(4);
                    392: [ 0 0 0 0 ]
                    393: [1] size(A);
                    394: [4]
                    395: [2] B = newmat(2,3,[[1,2,3],[4,5,6]]);
                    396: [ 1 2 3 ]
                    397: [ 4 5 6 ]
                    398: [3] size(B);
                    399: [2,3]
                    400: @end example
                    401:
                    402: @table @t
1.2       noro      403: \JP @item $B;2>H(B
                    404: \EG @item References
1.1       noro      405: @fref{car cdr cons append reverse length}, @fref{nmono}.
                    406: @end table
                    407:
1.5       noro      408: \JP @node det invmat,,, $BG[Ns(B
                    409: \EG @node det invmat,,, Arrays
                    410: @subsection @code{det},@code{invmat}
1.1       noro      411: @findex det
1.5       noro      412: @findex invmat
1.1       noro      413:
                    414: @table @t
                    415: @item det(@var{mat}[,@var{mod}])
1.2       noro      416: \JP :: @var{mat} $B$N9TNs<0$r5a$a$k(B.
                    417: \EG :: Determinant of @var{mat}.
1.5       noro      418: @item invmat(@var{mat})
1.8     ! takayama  419: \JP :: @var{mat} $B$N5U9TNs$r5a$a$k(B.
1.5       noro      420: \EG :: Inverse matrix of @var{mat}.
1.1       noro      421: @end table
                    422:
                    423: @table @var
                    424: @item return
1.5       noro      425: \JP @code{det}: $B<0(B, @code{invmat}: $B%j%9%H(B
                    426: \EG @code{det}: expression, @code{invmat}: list
1.1       noro      427: @item mat
1.2       noro      428: \JP $B9TNs(B
                    429: \EG matrix
1.1       noro      430: @item mod
1.2       noro      431: \JP $BAG?t(B
                    432: \EG prime
1.1       noro      433: @end table
                    434:
                    435: @itemize @bullet
1.2       noro      436: \BJP
1.1       noro      437: @item
1.5       noro      438: @code{det} $B$O9TNs(B @var{mat} $B$N9TNs<0$r5a$a$k(B.
                    439: @code{invmat} $B$O9TNs(B @var{mat} $B$N5U9TNs$r5a$a$k(B. $B5U9TNs$O(B @code{[$BJ,Jl(B, $BJ,;R(B]}
                    440: $B$N7A$GJV$5$l(B, @code{$BJ,Jl(B}$B$,9TNs(B, @code{$BJ,Jl(B/$BJ,;R(B} $B$,5U9TNs$H$J$k(B.
1.1       noro      441: @item
                    442: $B0z?t(B @var{mod} $B$,$"$k;~(B, GF(@var{mod}) $B>e$G$N9TNs<0$r5a$a$k(B.
                    443: @item
                    444: $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
                    445: $B9TNs$KBP$7$F$O>.9TNs<0E83+$K$h$kJ}K!$N$[$&$,8zN($,$h$$>l9g$b$"$k(B.
1.2       noro      446: \E
                    447: \BEG
                    448: @item
1.5       noro      449: @code{det} computes the determinant of matrix @var{mat}.
                    450: @code{invmat} computes the inverse matrix of matrix @var{mat}.
                    451: @code{invmat} returns a list @code{[num,den]}, where @code{num}
                    452: is a matrix and @code{num/den} represents the inverse matrix.
1.2       noro      453: @item
                    454: The computation is done over GF(@var{mod}) if @var{mod} is specitied.
                    455: @item
                    456: The fraction free Gaussian algorithm is employed.  For matrices with
                    457: multi-variate polynomial entries, minor expansion algorithm sometimes
                    458: is more efficient than the fraction free Gaussian algorithm.
                    459: \E
1.1       noro      460: @end itemize
                    461:
                    462: @example
                    463: [91] A=newmat(5,5)$
                    464: [92] V=[x,y,z,u,v];
                    465: [x,y,z,u,v]
                    466: [93] for(I=0;I<5;I++)for(J=0,B=A[I],W=V[I];J<5;J++)B[J]=W^J;
                    467: [94] A;
                    468: [ 1 x x^2 x^3 x^4 ]
                    469: [ 1 y y^2 y^3 y^4 ]
                    470: [ 1 z z^2 z^3 z^4 ]
                    471: [ 1 u u^2 u^3 u^4 ]
                    472: [ 1 v v^2 v^3 v^4 ]
                    473: [95] fctr(det(A));
1.7       noro      474: [[1,1],[u-v,1],[-z+v,1],[-z+u,1],[-y+u,1],[y-v,1],[-y+z,1],[-x+u,1],
                    475: [-x+z,1],[-x+v,1],[-x+y,1]]
1.5       noro      476: [96] A = newmat(3,3)$
                    477: [97] for(I=0;I<3;I++)for(J=0,B=A[I],W=V[I];J<3;J++)B[J]=W^J;
                    478: [98] A;
                    479: [ 1 x x^2 ]
                    480: [ 1 y y^2 ]
                    481: [ 1 z z^2 ]
                    482: [99] invmat(A);
                    483: [[ -z*y^2+z^2*y z*x^2-z^2*x -y*x^2+y^2*x ]
                    484: [ y^2-z^2 -x^2+z^2 x^2-y^2 ]
                    485: [ -y+z x-z -x+y ],(-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y]
                    486: [100] A*B[0];
                    487: [ (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 0 ]
                    488: [ 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 ]
                    489: [ 0 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y ]
                    490: [101] map(red,A*B[0]/B[1]);
                    491: [ 1 0 0 ]
                    492: [ 0 1 0 ]
                    493: [ 0 0 1 ]
1.1       noro      494: @end example
                    495:
                    496: @table @t
1.2       noro      497: \JP @item $B;2>H(B
                    498: \EG @item References
1.1       noro      499: @fref{newmat}.
                    500: @end table
                    501:
1.2       noro      502: \JP @node qsort,,, $BG[Ns(B
                    503: \EG @node qsort,,, Arrays
1.1       noro      504: @subsection @code{qsort}
                    505: @findex qsort
                    506:
                    507: @table @t
                    508: @item qsort(@var{array}[,@var{func}])
1.2       noro      509: \JP :: $B0l<!85G[Ns(B @var{array} $B$r%=!<%H$9$k(B.
                    510: \EG :: Sorts an array @var{array}.
1.1       noro      511: @end table
                    512:
                    513: @table @var
                    514: @item return
1.2       noro      515: \JP @var{array} ($BF~NO$HF1$8(B; $BMWAG$N$_F~$lBX$o$k(B)
                    516: \EG @var{array} (The same as the input; Only the elements are exchanged.)
1.1       noro      517: @item array
1.2       noro      518: \JP $B0l<!85G[Ns(B
                    519: \EG array
1.1       noro      520: @item func
1.2       noro      521: \JP $BHf3SMQ4X?t(B
                    522: \EG function for comparison
1.1       noro      523: @end table
                    524:
                    525: @itemize @bullet
1.2       noro      526: \BJP
1.1       noro      527: @item
                    528: $B0l<!85G[Ns$r(B quick sort $B$G%=!<%H$9$k(B.
                    529: @item
                    530: $BHf3SMQ4X?t$,;XDj$5$l$F$$$J$$>l9g(B, $B%*%V%8%'%/%H$I$&$7$NHf3S7k2L$G(B
                    531: $B=g=x$,2<$N$b$N$+$i=g$KJB$Y49$($i$l$k(B.
                    532: @item
                    533: 0, 1, -1 $B$rJV$9(B 2 $B0z?t4X?t$,(B @var{func} $B$H$7$FM?$($i$l$?>l9g(B,
                    534: @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
                    535: $B$b$N$+$i=g$KJB$Y49$($i$l$k(B.
                    536: @item
                    537: $BG[Ns$O?7$?$K@8@.$5$l$:(B, $B0z?t$NG[Ns$NMWAG$N$_F~$lBX$o$k(B.
1.2       noro      538: \E
                    539: \BEG
                    540: @item
                    541: This function sorts an array by @var{quick sort}.
                    542: @item
                    543: If @var{func} is not specified, the built-in comparison function
                    544: is used and the array is sorted in increasing order.
                    545: @item
                    546: If a function of two arguments @var{func} which returns 0, 1, or -1
                    547: is provided, then an ordering is detemined so that
                    548: @code{A<B} if @code{@var{func}(A,B)=1} holds, and
                    549: the array is sorted in increasing order with respect to the ordering.
                    550: @item
                    551: The returned array is the same as the input. Only the elements
                    552: are exchanged.
                    553: \E
1.1       noro      554: @end itemize
                    555:
                    556: @example
                    557: [0] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]));
                    558: [ -1 0 1 2 3 4 6 6 7 9 ]
                    559: [1] def rev(A,B) @{ return A>B?-1:(A<B?1:0); @}
                    560: [2] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]),rev);
                    561: [ 9 7 6 6 4 3 2 1 0 -1 ]
                    562: @end example
                    563:
                    564: @table @t
1.2       noro      565: \JP @item $B;2>H(B
                    566: \EG @item References
1.1       noro      567: @fref{ord}, @fref{vars}.
                    568: @end table

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>