=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/builtin/array.texi,v retrieving revision 1.1 retrieving revision 1.10 diff -u -p -r1.1 -r1.10 --- OpenXM/src/asir-doc/parts/builtin/array.texi 1999/12/08 05:47:44 1.1 +++ OpenXM/src/asir-doc/parts/builtin/array.texi 2005/02/10 04:59:21 1.10 @@ -1,34 +1,50 @@ +@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/array.texi,v 1.9 2003/12/18 10:26:20 ohara Exp $ +\BJP @node 配列,,, 組み込み函数 @section 配列 +\E +\BEG +@node Arrays,,, Built-in Function +@section Arrays +\E @menu * newvect:: +* ltov:: * vtol:: +* newbytearray:: * newmat:: * size:: -* det:: +* det nd_det invmat:: + * qsort:: @end menu -@node newvect,,, 配列 +\JP @node newvect,,, 配列 +\EG @node newvect,,, Arrays @subsection @code{newvect} @findex newvect @table @t @item newvect(@var{len}[,@var{list}]) -:: 長さ @var{len} のベクトルを生成する. +\JP :: 長さ @var{len} のベクトルを生成する. +\EG :: Creates a new vector object with its length @var{len}. @end table @table @var @item return -ベクトル +\JP ベクトル +\EG vector @item len -自然数 +\JP 自然数 +\EG non-negative integer @item list -リスト +\JP リスト +\EG list @end table @itemize @bullet +\BJP @item 長さ @var{len} のベクトルを生成する. 第 2 引数がない場合, 各成分は 0 に初期化される. 第 2 引数がある場合, @@ -54,6 +70,60 @@ @item 函数の引数としてベクトルを渡した場合, 渡された函数は, そのベクトルの成分 を書き換えることができる. +\E +\BEG +@item +Creates a new vector object with its length @var{len} and its elements +all cleared to value 0. +If the second argument, a list, is given, the vector is initialized by +the list elements. +Elements are used from the first through the last. +If the list is short for initializing the full vector, +0's are filled in the remaining vector elements. +@item +Elements are indexed from 0 through @var{len}-1. Note that the first +element has not index 1. +@item +List and vector are different types in @b{Asir}. +Lists are conveniently used for representing many data objects whose +size varies dynamically as computation proceeds. +By its flexible expressive power, it is also conveniently used to +describe initial values for other structured objects as you see +for vectors. +Access for an element of a list is performed by following pointers to +next elements. By this, access costs for list elements differ for +each element. +In contrast to lists, vector elements can be accessed in a same time, +because they are accessed by computing displacements from the top memory +location of the vector object. + +Note also, in @b{Asir}, modification of an element of a vector causes +modification of the whole vector itself, +while modification of a list element does not cause the modification +of the whole list object. + +By this, in @b{Asir} language, +a vector element designator can be a left value of +assignment statement, but a list element designator can NOT be a left +value of assignment statement. + +@item +No distinction of column vectors and row vectors in @b{Asir}. +If a matrix is applied to a vector from left, the vector shall be taken +as a column vector, and if from right it shall be taken as a row vector. +@item +The length (or size or dimension) of a vector is given by function +@code{size()}. +@item +When a vector is passed to a function as its argument +(actual parameter), the vector element can be modified in that +function. + +@item +A vector is displayed in a similar format as for a list. +Note, however, there is a distinction: Elements of a vector are +separated simply by a `blank space', while those of a list by a `comma.' +\E @end itemize @example @@ -74,32 +144,92 @@ @end example @table @t -@item 参照 -@fref{newmat}, @fref{size}. +\JP @item 参照 +\EG @item References +@fref{newmat}, @fref{size}, @fref{ltov}, @fref{vtol}. @end table -@node vtol,,, 配列 +\JP @node ltov,,, 配列 +\EG @node ltov,,, Arrays +@subsection @code{ltov} +@findex ltov + +@table @t +@item ltov(@var{list}) +\JP :: リストをベクトルに変換する. +\EG :: Converts a list into a vector. +@end table + +@table @var +@item return +\JP ベクトル +\EG vector +@item list +\JP リスト +\EG list +@end table + +@itemize @bullet +\BJP +@item +リスト @var{list} を同じ長さのベクトルに変換する. +@item +この関数は @code{newvect(length(@var{list}), @var{list})} に等しい. +\E +\BEG +@item +Converts a list @var{list} into a vector of same length. +See also @code{newvect()}. +\E +@end itemize + +@example +[3] A=[1,2,3]; +[4] ltov(A); +[ 1 2 3 ] +@end example + +@table @t +\JP @item 参照 +\EG @item References +@fref{newvect}, @fref{vtol}. +@end table + +\JP @node vtol,,, 配列 +\EG @node vtol,,, Arrays @subsection @code{vtol} @findex vtol @table @t @item vtol(@var{vect}) -:: ベクトルをリストに変換する. +\JP :: ベクトルをリストに変換する. +\EG :: Converts a vector into a list. @end table @table @var @item return -リスト +\JP リスト +\EG list @item vect -ベクトル +\JP ベクトル +\EG vector @end table @itemize @bullet +\BJP @item 長さ @var{n} のベクトル @var{vect} を @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]} なるリストに変換する. @item リストからベクトルへの変換は @code{newvect()} で行う. +\E +\BEG +@item +Converts a vector @var{vect} of length @var{n} into +a list @code{[@var{vect}[0],...,@var{vect}[@var{n}-1]]}. +@item +A conversion from a list to a vector is done by @code{newvect()}. +\E @end itemize @example @@ -110,29 +240,92 @@ @end example @table @t -@item 参照 +\JP @item 参照 +\EG @item References +@fref{newvect}, @fref{ltov}. +@end table + +\JP @node newbytearray,,, 配列 +\EG @node newbytearray,,, Arrays +@subsection @code{newbytearray} +@findex newbytearray + +@table @t +@item newbytearray(@var{len},[@var{listorstring}]) +\JP :: 長さ @var{len} の byte array を生成する. +\EG :: Creates a new byte array. +@end table + +@table @var +@item return +byte array +@item len +\JP 自然数 +\EG non-negative integer +@item listorstring +\JP リストまたは文字列 +\EG list or string +@end table + +@itemize @bullet +@item +\JP @code{newvect} と同様にして byte array を生成する. +\EG This function generates a byte array. The specification is +similar to that of @code{newvect}. +@item +\JP 文字列で初期値を指定することも可能である. +\EG The initial value can be specified by a character string. +@item +\JP byte array の要素のアクセスは配列と同様である. +\EG One can access elements of a byte array just as an array. +@end itemize + +@example +[182] A=newbytearray(3); +|00 00 00| +[183] A=newbytearray(3,[1,2,3]); +|01 02 03| +[184] A=newbytearray(3,"abc"); +|61 62 63| +[185] A[0]; +97 +[186] A[1]=123; +123 +[187] A; +|61 7b 63| +@end example + +@table @t +\JP @item 参照 +\EG @item References @fref{newvect}. @end table -@node newmat,,, 配列 +\JP @node newmat,,, 配列 +\EG @node newmat,,, Arrays @subsection @code{newmat} @findex newmat @table @t -@item newmat(@var{row},@var{col} [,@var{[[a,b,}...@var{],[c,d,}...@var{],}...@var{]}]) -:: @var{row} 行 @var{col} 列の行列を生成する. +@item newmat(@var{row},@var{col} [,[[@var{a},@var{b},...],[@var{c},@var{d},...],...]]) +\JP :: @var{row} 行 @var{col} 列の行列を生成する. +\EG :: Creates a new matrix with @var{row} rows and @var{col} columns. @end table @table @var @item return -行列 -@item row,col -自然数 -@item a,b,c,d -任意 +\JP 行列 +\EG matrix +@item row col +\JP 自然数 +\EG non-negative integer +@item a b c d +\JP 任意 +\EG arbitrary @end table @itemize @bullet +\BJP @item @var{row} 行 @var{col} 列の行列を生成する. 第 3 引数がない場合, 各成分は 0 に初期化される. 第 3 引数がある場合, @@ -148,6 +341,29 @@ @item 函数の引数として行列を渡した場合, 渡された函数は, その行列の成分 を書き換えることができる. +\E +\BEG +@item +If the third argument, a list, is given, the newly created matrix +is initialized so that each element of the list (again a list) +initializes each of the rows of the matrix. +Elements are used from the first through the last. +If the list is short, 0's are filled in the remaining matrix elements. +If no third argument is given all the elements are cleared to 0. +@item +The size of a matrix is given by function @code{size()}. +@item +Let @code{M} be a program variable assigned to a matrix. +Then, @code{M[I]} denotes a (row) vector which corresponds with +the @code{I}-th row of the matrix. +Note that the vector shares its element with the original matrix. +Subsequently, if an element of the vector is modified, then the +corresponding matrix element is also modified. +@item +When a matrix is passed to a function as its argument +(actual parameter), the matrix element can be modified within that +function. +\E @end itemize @example @@ -167,33 +383,58 @@ return to toplevel @end example @table @t -@item 参照 -@fref{newvect}, @fref{size}, @fref{det}. +\JP @item 参照 +\EG @item References +@fref{newvect}, @fref{size}, @fref{det nd_det invmat}. @end table -@node size,,, 配列 +\JP @node size,,, 配列 +\EG @node size,,, Arrays @subsection @code{size} @findex size @table @t @item size(@var{vect|mat}) -:: @code{[@var{vect} の長さ]} または @code{[@var{mat} の行数,@var{mat} の列数]}. +\JP :: @code{[@var{vect} の長さ]} または @code{[@var{mat} の行数,@var{mat} の列数]}. +\BEG +:: A list containing the number of elements of the given vector, +@code{[size of @var{vect}]}, +or a list containing row size and column size of the given matrix, +@code{[row size of @var{mat}, column size of @var{mat}]}. +\E @end table @table @var @item return -リスト +\JP リスト +\EG list @item vect -ベクトル +\JP ベクトル +\EG vector @item mat -行列 +\JP 行列 +\EG matrix @end table @itemize @bullet +\BJP @item -@var{vect} 又は, @var{mat} のサイズをリストで出力する. +@var{vect} の長さ, または @var{mat} の大きさをリストで出力する. @item -@var{list} のサイズは @code{length()}を, 有理式に現れる単項式の数は @code{nmono()} を用いる. +@var{vect} の長さは @code{length()} で求めることもできる. +@item +@var{list} の長さは @code{length()}を, 有理式に現れる単項式の数は @code{nmono()} を用いる. +\E +\BEG +@item +Return a list consisting of the dimension of the vector @var{vect}, +or a list consisting of the row size and column size of the matrix +@var{matrix}. +@item +Use @code{length()} for the size of @var{list}, and +@code{nmono()} for the number of monomials with non-zero coefficients +in a rational expression. +\E @end itemize @example @@ -201,44 +442,84 @@ return to toplevel [ 0 0 0 0 ] [1] size(A); [4] -[2] B = newmat(2,3,[[1,2,3],[4,5,6]]); +[2] length(A); +4 +[3] B = newmat(2,3,[[1,2,3],[4,5,6]]); [ 1 2 3 ] [ 4 5 6 ] -[3] size(B); +[4] size(B); [2,3] @end example @table @t -@item 参照 +\JP @item 参照 +\EG @item References @fref{car cdr cons append reverse length}, @fref{nmono}. @end table -@node det,,, 配列 -@subsection @code{det} +\JP @node det nd_det invmat,,, 配列 +\EG @node det nd_det invmat,,, Arrays +@subsection @code{det},@code{invmat} @findex det +@findex invmat @table @t @item det(@var{mat}[,@var{mod}]) -:: @var{mat} の行列式を求める. +@itemx nd_det(@var{mat}[,@var{mod}]) +\JP :: @var{mat} の行列式を求める. +\EG :: Determinant of @var{mat}. +@item invmat(@var{mat}) +\JP :: @var{mat} の逆行列を求める. +\EG :: Inverse matrix of @var{mat}. @end table @table @var @item return -式 +\JP @code{det}: 式, @code{invmat}: リスト +\EG @code{det}: expression, @code{invmat}: list @item mat -行列 +\JP 行列 +\EG matrix @item mod -素数 +\JP 素数 +\EG prime @end table @itemize @bullet +\BJP @item -行列 @var{mat} の行列式を求める. +@code{det} および @code{nd_det} は行列 @var{mat} の行列式を求める. +@code{invmat} は行列 @var{mat} の逆行列を求める. 逆行列は @code{[分母, 分子]} +の形で返され, @code{分母}が行列, @code{分母/分子} が逆行列となる. @item 引数 @var{mod} がある時, GF(@var{mod}) 上での行列式を求める. @item 分数なしのガウス消去法によっているため, 多変数多項式を成分とする 行列に対しては小行列式展開による方法のほうが効率がよい場合もある. +@item +@code{nd_det} は有理数または有限体上の多項式行列の行列式 +計算専用である. アルゴリズムはやはり分数なしのガウス消去法だが, +データ構造および乗除算の工夫により, 一般に @code{det} より高速に +計算できる. +\E +\BEG +@item +@code{det} and @code{nd_det} compute the determinant of matrix @var{mat}. +@code{invmat} computes the inverse matrix of matrix @var{mat}. +@code{invmat} returns a list @code{[num,den]}, where @code{num} +is a matrix and @code{num/den} represents the inverse matrix. +@item +The computation is done over GF(@var{mod}) if @var{mod} is specitied. +@item +The fraction free Gaussian algorithm is employed. For matrices with +multi-variate polynomial entries, minor expansion algorithm sometimes +is more efficient than the fraction free Gaussian algorithm. +@item +@code{nd_det} can be used for computing the determinant of a matrix with +polynomial entries over the rationals or finite fields. The algorithm +is an improved vesion of the fraction free Gaussian algorithm +and it computes the determinant faster than @code{det}. +\E @end itemize @example @@ -253,34 +534,59 @@ return to toplevel [ 1 u u^2 u^3 u^4 ] [ 1 v v^2 v^3 v^4 ] [95] fctr(det(A)); -[[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], -[-x+v,1],[-x+y,1]] +[[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],[-x+v,1],[-x+y,1]] +[96] A = newmat(3,3)$ +[97] for(I=0;I<3;I++)for(J=0,B=A[I],W=V[I];J<3;J++)B[J]=W^J; +[98] A; +[ 1 x x^2 ] +[ 1 y y^2 ] +[ 1 z z^2 ] +[99] invmat(A); +[[ -z*y^2+z^2*y z*x^2-z^2*x -y*x^2+y^2*x ] +[ y^2-z^2 -x^2+z^2 x^2-y^2 ] +[ -y+z x-z -x+y ],(-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y] +[100] A*B[0]; +[ (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 0 ] +[ 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y 0 ] +[ 0 0 (-y+z)*x^2+(y^2-z^2)*x-z*y^2+z^2*y ] +[101] map(red,A*B[0]/B[1]); +[ 1 0 0 ] +[ 0 1 0 ] +[ 0 0 1 ] @end example @table @t -@item 参照 +\JP @item 参照 +\EG @item References @fref{newmat}. @end table -@node qsort,,, 配列 +\JP @node qsort,,, 配列 +\EG @node qsort,,, Arrays @subsection @code{qsort} @findex qsort @table @t @item qsort(@var{array}[,@var{func}]) -:: 一次元配列 @var{array} をソートする. +\JP :: 一次元配列 @var{array} をソートする. +\EG :: Sorts an array @var{array}. @end table @table @var @item return -@var{array} (入力と同じ; 要素のみ入れ替わる) +\JP @var{array} (入力と同じ; 要素のみ入れ替わる) +\EG @var{array} (The same as the input; Only the elements are exchanged.) @item array -一次元配列 +\JP 一次元配列 +\EG array @item func -比較用関数 +\JP 比較用関数 +\EG function for comparison @end table @itemize @bullet +\BJP @item 一次元配列を quick sort でソートする. @item @@ -292,6 +598,22 @@ return to toplevel ものから順に並べ換えられる. @item 配列は新たに生成されず, 引数の配列の要素のみ入れ替わる. +\E +\BEG +@item +This function sorts an array by @var{quick sort}. +@item +If @var{func} is not specified, the built-in comparison function +is used and the array is sorted in increasing order. +@item +If a function of two arguments @var{func} which returns 0, 1, or -1 +is provided, then an ordering is detemined so that +@code{A