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

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

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