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

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

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