[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.9

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

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