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

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

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