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