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