Annotation of OpenXM/doc/OpenXM-specs/cmo-basic1.tex, Revision 1.13
1.13 ! takayama 1: %% $OpenXM: OpenXM/doc/OpenXM-specs/cmo-basic1.tex,v 1.12 2002/01/20 09:26:21 takayama Exp $
1.1 noro 2: //&jp \section{ 数, 多項式 の CMO 表現 }
3: //&eg \section{ CMOexpressions for numbers and polynomials }
1.4 noro 4: \label{sec:basic1}
1.1 noro 5: /*&C
6: @../SSkan/plugin/cmotag.h
7: \begin{verbatim}
8: #define CMO_MONOMIAL32 19
9: #define CMO_ZZ 20
10: #define CMO_QQ 21
11: #define CMO_ZERO 22
12: #define CMO_DMS_GENERIC 24
13: #define CMO_DMS_OF_N_VARIABLES 25
14: #define CMO_RING_BY_NAME 26
15: #define CMO_DISTRIBUTED_POLYNOMIAL 31
16: #define CMO_RATIONAL 34
17:
18:
19: #define CMO_INDETERMINATE 60
20: #define CMO_TREE 61
21: #define CMO_LAMBDA 62 /* for function definition */
22: \end{verbatim}
23:
24: */
25:
26: /*&jp
1.4 noro 27: 以下, グループ CMObject/Basic, CMObject/Tree
1.1 noro 28: および CMObject/DistributedPolynomial
29: に属する CMObject の形式を説明する.
30:
1.5 noro 31: \noindent
32: {\tt OpenXM/src/ox\_toolkit} にある {\tt bconv} をもちいると
33: CMO expression を binary format に変換できるので,
34: これを参考にするといい.
1.1 noro 35: */
36: /*&eg
37: In the sequel, we will explain on the groups
1.4 noro 38: CMObject/Basic, CMObject/Tree
1.1 noro 39: and CMObject/DistributedPolynomial.
1.5 noro 40:
41: \noindent
42: The program {\tt bconv} at {\tt OpenXM/src/ox\_toolkit}
43: translates
44: CMO expressions into binary formats.
45: It is convinient to understand the binary formats explained in
46: this section.
1.1 noro 47: */
48:
1.5 noro 49: /*&C
50: \noindent Example:
51: \begin{verbatim}
52: bash$ ./bconv
53: > (CMO_ZZ,123123);
54: 00 00 00 14 00 00 00 01 00 01 e0 f3
55: \end{verbatim}
56: */
1.1 noro 57: /*&jp
58:
59: \bigbreak
60: \noindent
1.4 noro 61: Group CMObject/Basic requires CMObject/Primitive. \\
1.12 takayama 62: ZZ, QQ, Zero, Rational, Indeterminate $\in$ CMObject/Basic. \\
1.1 noro 63: \begin{eqnarray*}
64: \mbox{Zero} &:& ({\tt CMO\_ZERO}) \\
65: & & \mbox{ --- ユニバーサルな ゼロを表す. } \\
1.12 takayama 66: \mbox{ZZ} &:& ({\tt CMO\_ZZ},{\sl int32}\, {\rm f}, {\sl byte}\, \mbox{a[1]}, \ldots ,
1.9 noro 67: {\sl byte}\, \mbox{a[$|$f$|$]} ) \\
1.1 noro 68: &:& \mbox{ --- bignum をあらわす. a[i] についてはあとで説明}\\
1.9 noro 69: \mbox{QQ} &:& ({\tt CMO\_QQ},
70: {\sl int32}\, {\rm m}, {\sl byte}\, \mbox{a[1]}, \ldots, {\sl byte}\, \mbox{a[$|$m$|$]},
71: {\sl int32}\, {\rm n}, {\sl byte}\, \mbox{b[1]}, \ldots, {\sl byte}\, \mbox{b[$|$n$|$]})\\
1.1 noro 72: & & \mbox{ --- 有理数 $a/b$ を表す. } \\
73: \mbox{Rational} &:& ({\tt CMO\_RATIONAL}, {\sl CMObject}\, {\rm a}, {\sl CMObject}\, {\rm b}) \\
74: & & \mbox{ --- $a/b$ を表す. } \\
75: \mbox{Indeterminate} &:& ({\tt CMO\_INDETERMINATE}, {\sl Cstring}\, {\rm v}) \\
76: & & \mbox{ --- 変数名 $v$ . } \\
77: \end{eqnarray*}
78: */
1.12 takayama 79:
80:
1.1 noro 81: /*&eg
82:
83: \bigbreak
84: \noindent
1.4 noro 85: Group CMObject/Basic requires CMObject/Primitive. \\
1.12 takayama 86: ZZ, QQ, Zero, Rational, Indeterminate $\in$ CMObject/Basic. \\
1.1 noro 87: \begin{eqnarray*}
88: \mbox{Zero} &:& ({\tt CMO\_ZERO}) \\
89: & & \mbox{ --- Universal zero } \\
1.12 takayama 90: \mbox{ZZ} &:& ({\tt CMO\_ZZ},{\sl int32}\, {\rm f}, {\sl byte}\, \mbox{a[1]}, \ldots ,
1.9 noro 91: {\sl byte}\, \mbox{a[$|$m$|$]} ) \\
1.1 noro 92: &:& \mbox{ --- bignum. The meaning of a[i] will be explained later.}\\
1.9 noro 93: \mbox{QQ} &:& ({\tt CMO\_QQ},
94: {\sl int32}\, {\rm m}, {\sl byte}\, \mbox{a[1]}, \ldots, {\sl byte}\, \mbox{a[$|$m$|$]},
95: {\sl int32}\, {\rm n}, {\sl byte}\, \mbox{b[1]}, \ldots, {\sl byte}\, \mbox{b[$|$n$|$]})\\
1.1 noro 96: & & \mbox{ --- Rational number $a/b$. } \\
97: \mbox{Rational} &:& ({\tt CMO\_RATIONAL}, {\sl CMObject}\, {\rm a}, {\sl CMObject}\, {\rm b}) \\
98: & & \mbox{ --- Rational expression $a/b$. } \\
99: \mbox{Indeterminate} &:& ({\tt CMO\_INDETERMINATE}, {\sl Cstring}\, {\rm v}) \\
100: & & \mbox{ --- Variable name $v$ . } \\
101: \end{eqnarray*}
102: */
103: /*&C
104:
105: */
1.12 takayama 106: /*&C
107:
108: */
1.1 noro 109:
110: /*&jp
111: Indeterminate は変数名をあらわす.
112: v はバイト列であればなにを用いてもよいが,
113: システム毎に変数名として用いられるバイト列は制限がある.
114: 各システム xxx は任意の文字列を各システム固有の変数名へ1対1に変換できるように
115: 実装しないといけない.
116: (これを
117: {\tt Dx} は {\tt \#dx} と変換するなどの
118: escape sequence を用いて実現するのは, 無理があるようである.
119: テーブルを作成する必要があるであろう.)
120: */
121: /*&eg
1.12 takayama 122: The name of a variable should be expressed by using Indeterminate.
1.1 noro 123: v may be any sequence of bytes, but each system has its own
124: restrictions on the names of variables.
125: Indeterminates of CMO and internal variable names must be translated
1.12 takayama 126: in one-to-one correspondence.
1.1 noro 127: */
128:
1.12 takayama 129:
1.1 noro 130: /*&jp
1.12 takayama 131: \subsection{Indeterminate および Tree}
1.1 noro 132:
133: \noindent
1.4 noro 134: Group CMObject/Tree requires CMObject/Basic. \\
1.12 takayama 135: Tree, Lambda $\in$ CMObject/Tree. \\
1.1 noro 136: \begin{eqnarray*}
137: \mbox{Tree} &:& ({\tt CMO\_TREE}, {\sl Cstring}\, {\rm name},
1.11 takayama 138: {\sl List}\, {\rm attributes}, {\sl List}\, {\rm leaves}) \\
1.1 noro 139: & & \mbox{ --- 名前 name の定数または関数. 関数の評価はおこなわない. } \\
1.11 takayama 140: & & \mbox{ --- attributes は空リストでなければ name の属性を保持している. }\\
141: & & \mbox{ --- 属性リストは, key と 値のペアである. }\\
1.1 noro 142: \mbox{Lambda} &:& ({\tt CMO\_LAMBDA}, {\sl List}\, {\rm args},
143: {\sl Tree} {\rm body}) \\
144: & & \mbox{ --- body を args を引数とする関数とする. } \\
145: \end{eqnarray*}
146: */
147: /*&eg
1.12 takayama 148: \subsection{Indeterminate and Tree}
1.1 noro 149:
150: \noindent
1.4 noro 151: Group CMObject/Tree requires CMObject/Basic. \\
1.12 takayama 152: Tree, Lambda $\in$ CMObject/Tree. \\
1.1 noro 153: \begin{eqnarray*}
154: \mbox{Tree} &:& ({\tt CMO\_TREE}, {\sl Cstring}\, {\rm name},
1.11 takayama 155: {\sl List}\, {\rm attributes}, {\sl List}\, {\rm leaves}) \\
1.12 takayama 156: & & \mbox{ --- ``name'' is the name of the node of the tree. } \\
157: & & \mbox{ --- Attributes may be a null list. If it is not null, it is a list of}\\
1.11 takayama 158: & & \mbox{ --- key and value pairs. } \\
1.1 noro 159: \mbox{Lambda} &:& ({\tt CMO\_LAMBDA}, {\sl List}\, {\rm args},
160: {\sl Tree} {\rm body}) \\
161: & & \mbox{ --- a function with the arguments body. } \\
162: \end{eqnarray*}
163: */
164:
165: /*&jp
166: 数式を処理するシステムでは, Tree 構造が一般にもちいられる.
167: たとえば, $\sin(x+e)$ は,
168: {\tt (sin, (plus, x, e))}
169: なる Tree であらわすのが一般的である.
170: Tree の表現を スタックマシンのレベルでおこなうとすると,
171: {\tt ox\_BEGIN\_BLOCK}, {\tt ox\_END\_BLOCK} で評価を抑制するのが
172: 一つの方法である (cf. Postscript の {\tt \{ }, {\tt \} }).
173: たとえば上の方法では
174: {\tt x, e, plus, sin } を begin block, end block でかこめばよろしい.
175: われわれはスタックマシンの実装をなるべく簡単にするという立場をとりたい,
176: また数学オブジェクトを OX スタックマシンと CMObject を混在して表現したく
177: ない.
178: したがって,
179: Tree 構造は Open Math 風の表現をもちいた CMO を導入することにした.
180: またこのほうが, われわれの想定するシステム xxx において, Open XM 対応が
181: はるかに容易である.
182: なお, Tree は, Open Math では, Symbol, Application のメカニズムに相当する.
183: */
184: /*&eg
185: In many computer algebra systems, mathematical expressions are usually
186: expressed in terms of a tree structure.
187: For example,
188: $\sin(x+e)$ is expressed as
189: {\tt (sin, (plus, x, e))}
190: as a tree.
1.4 noro 191: Tree may be expressed by putting the expression between
1.3 noro 192: {\tt SM\_beginBlock} and {\tt SM\_endBlock}, which are
193: stack machine commands for delayed evaluation.
194: (cf. {\tt \{ }, {\tt \} } in PostScript).
195: However it makes the implementation of stack machines complicated.
196: It is desirable that CMObject is independent of OX stack machine.
197: Therefore we introduce an OpenMath like tree representation for CMO
1.7 noro 198: Tree object.
1.3 noro 199: This method allows us to implement tree structure easily
200: on individual OpenXM systems.
201: Note that CMO Tree corresponds to Symbol and Application in OpenMath.
1.1 noro 202: */
203:
204:
205: /*&C
206:
207: */
208: /*&jp
209: Lambda は関数を定義するための関数である.
210: Lisp の Lambda 表現と同じ.
1.3 noro 211: */
212: /*&eg
213: Lambda is used to define functions.
1.12 takayama 214: The notion ``lambda'' is borrowed from the language Lisp.
1.3 noro 215: */
1.1 noro 216:
217: \noindent
1.3 noro 218: //&jp 例: $sin(x+e)$ の表現.
219: //&eg Example: the expression of $sin(x+e)$.
1.1 noro 220: \begin{verbatim}
1.11 takayama 221: (CMO_TREE, (CMO_STRING, "sin"),
222: (CMO_LIST,[size=]1,(CMO_LIST,[size=]2,(CMO_STRING, "cdname"),
223: (CMO_STRING,"basic")))
1.1 noro 224: (CMO_LIST,[size=]1,
225: (CMO_TREE, (CMO_STRING, "plus"), (CMO_STRING, "basic"),
226: (CMO_LIST,[size=]2, (CMO_INDETERMINATE,"x"),
1.6 noro 227: //&jp (CMO_TREE,(CMO_STRING, "e"), 自然対数の底
228: //&eg (CMO_TREE,(CMO_STRING, "e"), the base of natural logarithms
1.12 takayama 229: (CMO_LIST,[size=]1,(CMO_LIST,[size=]2,(CMO_STRING, "cdname"),
230: (CMO_STRING,"basic")))
1.1 noro 231: ))
232: )
233: )
234: \end{verbatim}
1.10 takayama 235: //&jp Leave の成分には, 多項式を含む任意のオブジェクトがきてよい.
236: //&eg Elements of the leave may be any objects including polynomials.
1.1 noro 237:
238: \noindent
239: Example:
240: \begin{verbatim}
1.12 takayama 241: sm1> [(plus) [[(cdname) (basic)]] [(123).. (345)..]] [(class) (tree)] dc ::
242: Class.tree [$plus$ , [[$cdname$ , $basic$ ]], [ 123 , 345 ] ]
1.1 noro 243: \end{verbatim}
244:
1.12 takayama 245: \noindent
246: Example:
247: \begin{verbatim}
248: asir
249: [753] taka_cmo100_xml_form(quote(sin(x+1)));
250: <cmo_tree> <cmo_string>"sin"</cmo_string>
251: <cmo_list><cmo_int32 for="length">1</cmo_int32>
252: <cmo_list><cmo_int32 for="length">2</cmo_int32>
253: <cmo_string>"cdname"</cmo_string>
254: <cmo_string>"basic"</cmo_string>
255: </cmo_list> </cmo_list>
256: <cmo_tree> <cmo_string>"plus"</cmo_string>
257: <cmo_list><cmo_int32 for="length">1</cmo_int32>
258: <cmo_list><cmo_int32 for="length">2</cmo_int32>
259: <cmo_string>"cdname"</cmo_string>
260: <cmo_string>"basic"</cmo_string>
261: </cmo_list> </cmo_list>
262: <cmo_indeterminate> <cmo_string>"x"</cmo_string> </cmo_indeterminate>
263: <cmo_zz>1</cmo_zz>
264: </cmo_tree></cmo_tree>
265: \end{verbatim}
1.1 noro 266:
267:
268: \bigbreak
1.3 noro 269: //&jp 次に, 分散表現多項式に関係するグループを定義しよう.
1.4 noro 270: /*&eg
1.12 takayama 271: Let us define a group for distributed polynomials. In the following,
1.4 noro 272: DMS stands for Distributed Monomial System.
273: */
1.1 noro 274:
275: \medbreak
276: \noindent
1.4 noro 277: Group CMObject/DistributedPolynomials requires CMObject/Primitive,
278: CMObject/Basic. \\
1.1 noro 279: Monomial, Monomial32, Coefficient, Dpolynomial, DringDefinition,
280: Generic DMS ring, RingByName, DMS of N variables $\in$
281: CMObject/DistributedPolynomials. \\
1.3 noro 282: /*&jp
1.1 noro 283: \begin{eqnarray*}
284: \mbox{Monomial} &:& \mbox{Monomial32}\, |\, \mbox{Zero} \\
285: \mbox{Monomial32}&:& ({\tt CMO\_MONOMIAL32}, {\sl int32}\, n,
286: {\sl int32}\, \mbox{e[1]}, \ldots,
287: {\sl int32}\, \mbox{e[n]}, \\
288: & & \ \mbox{Coefficient}) \\
289: & & \mbox{ --- e[i] で, $n$ 変数 monomial
290: $x^e = x_1^{e_1} \cdots x_n^{e_n}$ の各指数 $e_i$
291: をあらわす.} \\
292: \mbox{Coefficient}&:& \mbox{ZZ} | \mbox{Integer32} \\
293: \mbox{Dpolynomial}&:& \mbox{Zero} \\
1.12 takayama 294: & & |\ ({\tt CMO\_DISTRIBUTED\_POLYNOMIAL},{\sl int32}\, m, \\
1.1 noro 295: & & \ \ \mbox{DringDefinition},
296: [\mbox{Monomial32}|\mbox{Zero}], \\
297: & &\ \
298: \{\mbox{Monomial32}\}) \\
299: & &\mbox{--- m はモノミアルの個数である.}\\
300: \mbox{DringDefinition}
301: &:& \mbox{DMS of N variables} \\
302: & & |\ \mbox{RingByName} \\
303: & & |\ \mbox{Generic DMS ring} \\
304: & & \mbox{ --- 分散表現多項式環の定義. } \\
305: \mbox{Generic DMS ring}
1.2 noro 306: &:& \mbox{({\tt CMO\_DMS\_GENERIC}) --- 新版はこちら}\\
1.1 noro 307: \mbox{RingByName}&:& ({\tt CMO\_RING\_BY\_NAME}, {\sl Cstring}\ {\rm s}) \\
308: & & \mbox{ --- 名前 s で, 格納された ring 定義.} \\
309: \mbox{DMS of N variables}
310: &:& ({\tt CMO\_DMS\_OF\_N\_VARIABLES}, \\
311: & & \ ({\tt CMO\_LIST}, {\sl int32}\, \mbox{m},
312: {\sl Integer32}\, \mbox{n}, {\sl Integer32}\,\mbox{p} \\
313: & & \ \ [,{\sl object}\,\mbox{s}, {\sl Cstring}\,\mbox{c},
314: {\sl List}\, \mbox{vlist},
315: {\sl List}\, \mbox{wvec}, {\sl List}\, \mbox{outord}]) \\
316: & & \mbox{ --- m はあとに続く要素の数} \\
317: & & \mbox{ --- n は変数の数, p は 標数} \\
318: & & \mbox{ --- s は ring の名前} \\
319: & & \mbox{ --- c は係数環, QQ, ZZ の場合は文字列で QQ, ZZ と書く.} \\
320: & & \mbox{ --- vlist は Indeterminate のリスト(新版). 多項式環の変数リスト} \\
321: & & \mbox{ --- wvec は order をきめる weight vector,} \\
322: & & \mbox{ --- outord は出力するときの変数順序.} \\
323: \end{eqnarray*}
1.3 noro 324: */
325: /*&eg
326: \begin{eqnarray*}
327: \mbox{Monomial} &:& \mbox{Monomial32}\, |\, \mbox{Zero} \\
328: \mbox{Monomial32}&:& ({\tt CMO\_MONOMIAL32}, {\sl int32}\, n,
329: {\sl int32}\, \mbox{e[1]}, \ldots,
330: {\sl int32}\, \mbox{e[n]}, \\
331: & & \ \mbox{Coefficient}) \\
332: & & \mbox{ --- e[i] is the exponent $e_i$ of the monomial
333: $x^e = x_1^{e_1} \cdots x_n^{e_n}$. } \\
334: \mbox{Coefficient}&:& \mbox{ZZ} | \mbox{Integer32} \\
335: \mbox{Dpolynomial}&:& \mbox{Zero} \\
1.12 takayama 336: & & |\ ({\tt CMO\_DISTRIBUTED\_POLYNOMIAL},{\sl int32}\, m, \\
1.3 noro 337: & & \ \ \mbox{DringDefinition}, [\mbox{Monomial32}|\mbox{Zero}], \\
338: & &\ \
339: \{\mbox{Monomial32}\}) \\
340: & &\mbox{--- m is equal to the number of monomials.}\\
341: \mbox{DringDefinition}
342: &:& \mbox{DMS of N variables} \\
343: & & |\ \mbox{RingByName} \\
344: & & |\ \mbox{Generic DMS ring} \\
345: & & \mbox{ --- definition of the ring of distributed polynomials. } \\
346: \mbox{Generic DMS ring}
347: &:& ({\tt CMO\_DMS\_GENERIC}) \\
348: \mbox{RingByName}&:& ({\tt CMO\_RING\_BY\_NAME}, {\sl Cstring} s) \\
1.4 noro 349: & & \mbox{ --- The ring definition referred by the name ``s''.} \\
1.3 noro 350: \mbox{DMS of N variables}
351: &:& ({\tt CMO\_DMS\_OF\_N\_VARIABLES}, \\
352: & & \ ({\tt CMO\_LIST}, {\sl int32}\, \mbox{m},
353: {\sl Integer32}\, \mbox{n}, {\sl Integer32}\, \mbox{p} \\
354: & & \ \ [,{\sl Cstring}\,\mbox{s}, {\sl List}\, \mbox{vlist},
355: {\sl List}\, \mbox{wvec}, {\sl List}\, \mbox{outord}]) \\
356: & & \mbox{ --- m is the number of elements.} \\
357: & & \mbox{ --- n is the number of variables, p is the characteristic} \\
358: & & \mbox{ --- s is the name of the ring, vlist is the list of variables.} \\
359: & & \mbox{ --- wvec is the weight vector.} \\
360: & & \mbox{ --- outord is the order of variables to output.} \\
361: \end{eqnarray*}
362: */
1.1 noro 363:
1.3 noro 364: /*&jp
1.1 noro 365: RingByName や DMS of N variables はなくても, DMS を定義できる.
366: したがって, これらを実装してないシステムで DMS を扱うものが
367: あってもかまわない.
368:
369: 以下, 以上の CMObject にたいする,
370: xxx = asir, kan の振舞いを記述する.
1.3 noro 371: */
372: /*&eg
373: Note that it is possible to define DMS without RingByName and
374: DMS of N variables.
375:
376: In the following we describe how the above CMObjects
377: are implemented on Asir and Kan.
378: */
1.1 noro 379:
380: \subsection{ Zero}
1.3 noro 381: /*&jp
1.12 takayama 382: CMO では ゼロの表現法がなんとおりもあることに注意.
383: %% どのようなゼロをうけとっても,
384: %% システムのゼロに変換できるべきである.
1.3 noro 385: */
386: /*&eg
1.12 takayama 387: Note that CMO has various representations of zero.
1.3 noro 388: */
1.1 noro 389:
390:
1.3 noro 391: //&jp \subsection{ 整数 ZZ }
392: //&eg \subsection{ Integer ZZ }
1.1 noro 393:
394: \begin{verbatim}
395: #define CMO_ZZ 20
396: \end{verbatim}
397:
1.3 noro 398: /*&jp
399: この節ではOpen xxx 規約における任意の大きさの整数(bignum)の扱いについ
400: て説明する. Open XM 規約における多重精度整数を表すデータ型 CMO\_ZZ は
401: GNU MPライブラリなどを参考にして設計されていて, 符号付き絶対値表現を用
402: いている. (cf. {\tt kan/sm1} の配布ディレクトリのなかの {\tt
403: plugin/cmo-gmp.c}) CMO\_ZZ は次の形式をとる.
404: */
405: /*&eg
1.12 takayama 406: We describe the bignum (multi-precision integer) representation
407: {\tt CMO\_ZZ} in OpenXM.
408: The format is similar
1.3 noro 409: to that in GNU MP. (cf. {\tt plugin/cmo-gmp.c} in the {\tt kan/sm1}
410: distribution). CMO\_ZZ is defined as follows.
411: */
1.1 noro 412:
413: \begin{tabular}{|c|c|c|c|c|}
414: \hline
415: {\tt int32 CMO\_ZZ} & {\tt int32 $f$} & {\tt int32 $b_0$} & $\cdots$ &
416: {\tt int32 $b_{n}$} \\
417: \hline
1.3 noro 418: \end{tabular}
419:
420: /*&jp
421: $f$ は32bit整数である. $b_0, \ldots, b_n$ は unsigned int32 である.
422: $|f|$ は $n+1$ である. この CMO の符号は $f$ の符号で定める. 前述し
423: たように, 32bit整数の負数は 2 の補数表現で表される.
424:
425: Open xxx 規約では上の CMO は以下の整数を意味する. ($R = 2^{32}$)
426: */
427: /*&eg
428: $f$ is a 32bit integer. $b_0, \ldots, b_n$ are unsigned 32bit integers.
429: $|f|$ is equal to $n+1$.
1.12 takayama 430: The sign of $f$ represents that of the above integer to be expressed.
431: As stated in Section
1.3 noro 432: \ref{sec:basic0}, a negative 32bit integer is represented by
433: two's complement.
434:
435: In OpenXM the above CMO represents the following integer. ($R = 2^{32}$.)
436: */
1.1 noro 437:
438: \[
439: \mbox{sgn}(f)\times (b_0 R^{0}+ b_1 R^{1} + \cdots + b_{n-1}R^{n-1} + b_n R^n).
440: \]
1.3 noro 441:
442: /*&jp
1.12 takayama 443: \noindent 例:
1.3 noro 444: {\tt int32} を network byte order で表現
445: しているとすると,例えば, 整数 $14$ は CMO\_ZZ で表わすと,
446: */
447: /*&eg
1.12 takayama 448: \noindent Example:
1.3 noro 449: If we express {\tt int32} by the network byte order,
450: a CMO\_ZZ $14$ is expressed by
451: */
1.1 noro 452: \[
453: \mbox{(CMO\_ZZ, 1, 0, 0, 0, e)},
454: \]
1.3 noro 455: //&jp と表わす. これはバイト列では
1.4 noro 456: //&eg The corresponding byte sequence is
1.1 noro 457: \[
458: \mbox{\tt 00 00 00 14 00 00 00 01 00 00 00 0e}
459: \]
1.3 noro 460: //&jp となる.
1.1 noro 461:
462:
1.3 noro 463: //&jp なお ZZ の 0 ( (ZZ) 0 と書く ) は, {\tt (CMO\_ZZ, 00,00,00,00)} と表現する.
464: //&eg Note that CMO\_ZZ 0 is expressed by {\tt (CMO\_ZZ, 00,00,00,00)}.
1.1 noro 465:
466:
1.3 noro 467: //&jp \subsection{ 分散表現多項式 Dpolynomial }
468: //&eg \subsection{ Distributed polynomial Dpolynomial }
1.1 noro 469:
1.3 noro 470: /*&jp
1.1 noro 471: 環とそれに属する多項式は次のような考えかたであつかう.
472:
473: Generic DMS ring に属する元は,
474: 変数を $n$ 個持つ 適当な係数集合 $K$ を持つ多項式環 $K[x_1, \ldots, x_n]$
475: の元である.
476: 係数集合 $K$ がなにかは, 実際データを読み込み, Coefficient を見た段階で
477: わかる.
478: この環に属する多項式を CMO 形式でうけとった場合, 各サーバはその
479: サーバの対応する Object に変換しないといけない.
480: この変換の仕方は, 各サーバ毎にきめる.
481:
482: Asir の場合は, $K[x_1, \ldots, x_n]$ の元は分散表現多項式に変換される.
483: \noroa{ でも, order はどうなるの? }
484:
485: {\tt kan/sm1} の場合は事情は複雑である.
486: {\tt kan/sm1} は, Generic DMS ring にあたる クラスをもたない.
487: つまり, Default で存在する, $n$ 変数の分散表現多項式環は存在しないわけである.
488: したがって, {\tt kan/sm1} では, DMS of N variables が来た場合,
489: これを CurrentRing の元として読み込む. CurrentRing の変数の数が $n'$
490: で, $n' < n$ だと新しい多項式環を生成してデータを読み込む.
491: Order その他の optional 情報はすべて無視する.
492:
493: DMS の 2 番目のフィールドで,
494: Ring by Name を用いた場合, 現在の名前空間で変数 yyy に格納された ring object
495: の元として, この多項式を変換しなさいという意味になる.
496: {\tt kan/sm1} の場合, 環の定義は ring object として格納されており,
497: この ring object を 変数 yyy で参照することにより CMO としてうけとった
498: 多項式をこの ring の元として格納できる.
1.3 noro 499: */
1.1 noro 500:
1.3 noro 501: /*&eg
502: We treat polynomial rings and their elements as follows.
1.1 noro 503:
1.4 noro 504: Generic DMS ring is an $n$-variate polynomial ring $K[x_1, \ldots, x_n]$,
1.12 takayama 505: where $K$ is a coefficient set. $K$ is unknown in advance
1.4 noro 506: and it is determined when coefficients of an element are received.
507: When a server has received an element in Generic DMS ring,
1.3 noro 508: the server has to translate it into the corresponding local object
509: on the server. Each server has its own translation scheme.
510: In Asir such an element are translated into a distributed polynomial.
511: In {\tt kan/sm1} things are complicated.
1.4 noro 512: {\tt kan/sm1} does not have any class corresponding to Generic DMS ring.
1.3 noro 513: {\tt kan/sm1} translates a DMS of N variables into an element of
514: the CurrentRing.
515: If the CurrentRing is $n'$-variate and $n' < n$, then
1.12 takayama 516: an $n$-variate polynomial ring is newly created.
517:
1.3 noro 518:
1.4 noro 519: If RingByName ({\tt CMO\_RING\_BY\_NAME}, yyy)
1.3 noro 520: is specified as the second field of DMS,
521: it requests a sever to use a ring object whose name is yyy
522: as the destination ring for the translation.
523: */
1.1 noro 524:
525: \medbreak \noindent
1.3 noro 526: //&jp {\bf Example}: (すべての数の表記は 16 進表記)
527: //&eg {\bf Example}: (all numbers are represented in hexadecimal notation)
1.1 noro 528: {\footnotesize \begin{verbatim}
529: Z/11Z [6 variables]
530: (kxx/cmotest.sm1) run
531: [(x,y) ring_of_polynomials ( ) elimination_order 11 ] define_ring ;
532: (3x^2 y). cmo /ff set ;
533: [(cmoLispLike) 1] extension ;
534: ff ::
535: Class.CMO CMO StandardEncoding: size = 52, size/sizeof(int) = 13,
536: tag=CMO_DISTRIBUTED_POLYNOMIAL
537:
538: 0 0 0 1f 0 0 0 1 0 0 0 18 0 0 0 13 0 0 0 6
539: 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1
540: 0 0 0 0 0 0 0 2 0 0 0 3
541:
542: ff omc ::
543: (CMO_DISTRIBUTED_POLYNOMIAL[1f],[size=]1,(CMO_DMS_GENERIC[18],),
544: (CMO_MONOMIAL32[13],3*x^2*y),),
545: \end{verbatim} }
1.3 noro 546: /*&jp
547: $ 3 x^2 y$ は 6 変数の多項式環の 元としてみなされている.
548: */
549: /*&eg
550: $3 x^2 y$ is regarded as an element of a six-variate polynomial ring.
551: */
1.1 noro 552:
553:
1.3 noro 554: //&jp \subsection{再帰表現多項式の定義}
555: //&eg \subsection{Recursive polynomials}
1.1 noro 556:
557: \begin{verbatim}
558: #define CMO_RECURSIVE_POLYNOMIAL 27
559: #define CMO_POLYNOMIAL_IN_ONE_VARIABLE 33
560: \end{verbatim}
561:
1.4 noro 562: Group CMObject/RecursivePolynomial requires CMObject/Primitive, CMObject/Basic.\\
1.1 noro 563: Polynomial in 1 variable, Coefficient, Name of the main variable,
564: Recursive Polynomial, Ring definition for recursive polynomials
565: $\in$ CMObject/RecursivePolynomial \\
566:
1.3 noro 567: /*&jp
1.1 noro 568: \begin{eqnarray*}
569: \mbox{Polynomial in 1 variable} &:&
570: \mbox{({\tt CMO\_POLYNOMIAL\_IN\_ONE\_VARIABLE},\, {\sl int32}\, m, } \\
571: & & \quad \mbox{ Name of the main variable }, \\
1.12 takayama 572: & & \quad \mbox{ \{ {\sl int32} e, Coefficient \}} ) \\
1.1 noro 573: & & \mbox{ --- m はモノミアルの個数. } \\
574: & & \mbox{ --- e, Coefficieint はモノミアルを表現している. } \\
575: & & \mbox{ --- 順序の高い順にならべる. 普通は巾の高い順.} \\
576: & & \mbox{ --- e は 1変数多項式の巾をあらわす. } \\
577: \mbox{Coefficient} &:& \mbox{ ZZ} \,|\, \mbox{ QQ } \,|\,
578: \mbox{ integer32 } \,|\,
579: \mbox{ Polynomial in 1 variable } \\
580: & & \quad \,|\, \mbox{Tree} \,|\, \mbox{Zero} \,|\,\mbox{Dpolynomial}\\
581: \mbox{Name of the main variable } &:&
582: \mbox{ {\sl int32} v } \\
583: & & \mbox{ --- v は 変数番号 (0 からはじまる) を表す. } \\
584: \mbox{Recursive Polynomial} &:&
585: \mbox{ ( {\tt CMO\_RECURSIVE\_POLYNOMIAL}, } \\
1.3 noro 586: & & \quad \mbox{ RringDefinition, } \\
1.1 noro 587: & & \quad
1.12 takayama 588: \mbox{ Polynomial in 1 variable}\, | \, \mbox{Coefficient} ) \\
1.3 noro 589: \mbox{RringDefinition}
1.1 noro 590: & : & \mbox{ {\sl List} v } \\
1.10 takayama 591: & & \quad \mbox{ --- v は, 変数名(indeterminate) または Tree のリスト. } \\
1.1 noro 592: & & \quad \mbox{ --- 順序の高い順. } \\
593: \end{eqnarray*}
1.3 noro 594: */
595: /*&eg
596: \begin{eqnarray*}
597: \mbox{Polynomial in 1 variable} &:&
598: \mbox{({\tt CMO\_POLYNOMIAL\_IN\_ONE\_VARIABLE},\, {\sl int32}\, m, } \\
599: & & \quad \mbox{ Name of the main variable }, \\
1.12 takayama 600: & & \quad \mbox{ \{ {\sl int32} e, Coefficient \}} ) \\
1.4 noro 601: & & \mbox{ --- m is the number of monomials. } \\
602: & & \mbox{ --- A pair of e and Coefficient represents a monomial. } \\
1.3 noro 603: & & \mbox{ --- The pairs of e and Coefficient are sorted in the } \\
604: & & \mbox{ \quad decreasing order, usually with respect to e.} \\
605: & & \mbox{ --- e denotes an exponent of a monomial with respect to } \\
606: & & \mbox{ \quad the main variable. } \\
607: \mbox{Coefficient} &:& \mbox{ ZZ} \,|\, \mbox{ QQ } \,|\,
608: \mbox{ integer32 } \,|\,
609: \mbox{ Polynomial in 1 variable } \\
610: & & \quad \,|\, \mbox{Tree} \,|\, \mbox{Zero} \,|\,\mbox{Dpolynomial}\\
611: \mbox{Name of the main variable } &:&
612: \mbox{ {\sl int32} v } \\
613: & & \mbox{ --- v denotes a variable number. } \\
614: \mbox{Recursive Polynomial} &:&
615: \mbox{ ( {\tt CMO\_RECURSIVE\_POLYNOMIAL}, } \\
616: & & \quad \mbox{ RringDefinition, } \\
617: & & \quad
1.12 takayama 618: \mbox{ Polynomial in 1 variable}\, | \, \mbox{Coefficient} ) \\
1.3 noro 619: \mbox{RringDefinition}
620: & : & \mbox{ {\sl List} v } \\
1.10 takayama 621: & & \quad \mbox{ --- v is a list of names of indeterminates or trees. } \\
1.3 noro 622: & & \quad \mbox{ --- It is sorted in the decreasing order. } \\
623: \end{eqnarray*}
624: */
1.1 noro 625: \bigbreak
626: \noindent
1.3 noro 627: Example:
1.1 noro 628: \begin{verbatim}
629: (CMO_RECURSIEVE_POLYNOMIAL, ("x","y"),
630: (CMO_POLYNOMIAL_IN_ONE_VARIABLE, 2, 0, <--- "x"
631: 3, (CMO_POLYNOMIAL_IN_ONE_VARIABLE, 2, 1, <--- "y"
632: 5, 1234,
633: 0, 17),
634: 1, (CMO_POLYNOMIAL_IN_ONE_VARIABLE, 2, 1, <--- "y"
635: 10, 1,
636: 5, 31)))
637: \end{verbatim}
1.3 noro 638: //&jp これは,
639: //&eg This represents
640: $$ x^3 (1234 y^5 + 17 ) + x^1 (y^{10} + 31 y^5) $$
641: /*&jp
1.1 noro 642: をあらわす.
1.12 takayama 643: %%非可換多項式もこの形式であらわしたいので, 積の順序を上のように
644: %%すること. つまり, 主変数かける係数の順番.
1.3 noro 645: */
646: /*&eg
1.12 takayama 647: %%We intend to represent non-commutative polynomials with the
648: %%same form. In such a case, the order of products are defined
649: %%as above, that is a power of the main variable $\times$ a coeffcient.
650:
1.3 noro 651: */
1.1 noro 652:
653: \noindent
654: \begin{verbatim}
655: sm1
656: sm1>(x^2-h). [(class) (recursivePolynomial)] dc /ff set ;
657: sm1>ff ::
658: Class.recursivePolynomial h * ((-1)) + (x^2 * (1))
659: \end{verbatim}
660:
1.3 noro 661: //&jp \subsection{CPU依存の double }
662: //&eg \subsection{CPU dependent double}
1.1 noro 663:
664: \begin{verbatim}
665: #define CMO_64BIT_MACHINE_DOUBLE 40
666: #define CMO_ARRAY_OF_64BIT_MACHINE_DOUBLE 41
667: #define CMO_128BIT_MACHINE_DOUBLE 42
668: #define CMO_ARRAY_OF_128BIT_MACHINE_DOUBLE 43
669: \end{verbatim}
670:
671: \noindent
1.4 noro 672: Group CMObject/MachineDouble requires CMObject/Primitive.\\
1.1 noro 673: 64bit machine double, Array of 64bit machine double
674: 128bit machine double, Array of 128bit machine double
675: $\in$ CMObject/MachineDouble \\
676:
1.3 noro 677: /*&jp
1.1 noro 678: \begin{eqnarray*}
679: \mbox{64bit machine double} &:&
680: \mbox{({\tt CMO\_64BIT\_MACHINE\_DOUBLE}, } \\
1.12 takayama 681: & & \quad \mbox{ {\sl byte} s1 , \ldots , {\sl byte} s8})\\
1.1 noro 682: & & \mbox{ --- s1, $\ldots$, s8 は {\tt double} (64bit). } \\
683: & & \mbox{ --- この表現はCPU依存である.}\\
1.13 ! takayama 684: && \mbox{\quad\quad byte order negotiation を用いる.} \\
1.1 noro 685: \mbox{Array of 64bit machine double} &:&
686: \mbox{({\tt CMO\_ARRAY\_OF\_64BIT\_MACHINE\_DOUBLE}, {\sl int32} m, } \\
687: & & \quad \mbox{ {\sl byte} s1[1] , \ldots , {\sl byte}}\, s8[1], \ldots , {\sl byte}\, s8[m])\\
688: & & \mbox{ --- s*[1], $\ldots$ s*[m] は m 個の double (64bit) である. } \\
689: & & \mbox{ --- この表現はCPU依存である.}\\
1.13 ! takayama 690: & & \mbox{ \quad\quad byte order negotiation を用いる.} \\
1.1 noro 691: \mbox{128bit machine double} &:&
692: \mbox{({\tt CMO\_128BIT\_MACHINE\_DOUBLE}, } \\
1.12 takayama 693: & & \quad \mbox{ {\sl byte} s1 , \ldots , {\sl byte} s16})\\
1.1 noro 694: & & \mbox{ --- s1, $\ldots$, s16 は {\tt long double} (128bit). } \\
695: & & \mbox{ --- この表現はCPU依存である.}\\
1.13 ! takayama 696: && \mbox{\quad\quad byte order negotiation を用いる.} \\
1.1 noro 697: \mbox{Array of 128bit machine double} &:&
698: \mbox{({\tt CMO\_ARRAY\_OF\_128BIT\_MACHINE\_DOUBLE}, {\sl int32} m, } \\
1.12 takayama 699: & & \quad \mbox{ {\sl byte} s1[1] , \ldots , {\sl byte} s16[1], \ldots , {\sl byte} s16[m]})\\
1.1 noro 700: & & \mbox{ --- s*[1], $\ldots$ s*[m] は m 個の long double (128bit) である. } \\
701: & & \mbox{ --- この表現はCPU依存である.}\\
1.13 ! takayama 702: & & \mbox{ \quad\quad byte order negotiation を用いる.}
1.1 noro 703: \end{eqnarray*}
1.3 noro 704: */
705: /*&eg
706: \begin{eqnarray*}
707: \mbox{64bit machine double} &:&
708: \mbox{({\tt CMO\_64BIT\_MACHINE\_DOUBLE}, } \\
1.12 takayama 709: & & \quad \mbox{ {\sl byte} s1 , \ldots , {\sl byte} s8})\\
1.3 noro 710: & & \mbox{ --- s1, $\ldots$, s8 は {\tt double} (64bit). } \\
1.12 takayama 711: & & \mbox{ --- Encoding depends on CPU.}\\
1.13 ! takayama 712: && \mbox{\quad\quad Need the byte order negotiation.} \\
1.3 noro 713: \mbox{Array of 64bit machine double} &:&
714: \mbox{({\tt CMO\_ARRAY\_OF\_64BIT\_MACHINE\_DOUBLE}, {\sl int32} m, } \\
715: & & \quad \mbox{ {\sl byte} s1[1] , \ldots , {\sl byte}}\, s8[1], \ldots , {\sl byte}\, s8[m])\\
716: & & \mbox{ --- s*[1], $\ldots$ s*[m] are 64bit double's. } \\
1.12 takayama 717: & & \mbox{ --- Encoding depends on CPU.}\\
1.13 ! takayama 718: & & \mbox{\quad\quad Need the byte order negotiation.} \\
1.3 noro 719: \mbox{128bit machine double} &:&
720: \mbox{({\tt CMO\_128BIT\_MACHINE\_DOUBLE}, } \\
1.12 takayama 721: & & \quad \mbox{ {\sl byte} s1 , \ldots , {\sl byte} s16})\\
1.3 noro 722: & & \mbox{ --- s1, $\ldots$, s16 は {\tt long double} (128bit). } \\
1.12 takayama 723: & & \mbox{ --- Encoding depends on CPU.}\\
1.13 ! takayama 724: & & \mbox{\quad\quad Need the byte order negotiation.} \\
1.3 noro 725: \mbox{Array of 128bit machine double} &:&
726: \mbox{({\tt CMO\_ARRAY\_OF\_128BIT\_MACHINE\_DOUBLE}, {\sl int32} m, } \\
1.12 takayama 727: & & \quad \mbox{ {\sl byte} s1[1] , \ldots , {\sl byte} s16[1], \ldots , {\sl byte} s16[m]})\\
1.3 noro 728: & & \mbox{ --- s*[1], $\ldots$ s*[m] are 128bit long double's. } \\
1.12 takayama 729: & & \mbox{ --- Encoding depends on CPU.}\\
1.13 ! takayama 730: & & \mbox{\quad\quad Need the byte order negotiation.} \\
1.3 noro 731: \end{eqnarray*}
732: */
1.1 noro 733:
734: \bigbreak
1.12 takayama 735:
1.1 noro 736: \begin{verbatim}
737: #define CMO_BIGFLOAT 50
738: #define CMO_IEEE_DOUBLE_FLOAT 51
739: \end{verbatim}
740:
1.3 noro 741: /*&jp
742: IEEE 準拠の float については, IEEE 754 double precision floating-point
743: format (64 bit) の定義を見よ.
1.13 ! takayama 744:
! 745: 256.100006 の Intel Pentium の double64 での内部表現は
! 746: {\tt cd 0c 80 43 } \\
! 747: 256.100006 の PowerPC (Mac) の double64 での内部表現は
! 748: {\tt 43 80 0c cd }.
! 749: この例でみるように byte の順序が逆である.
! 750: エンジンスタートの時の byte order negotiation で byte の順序を指定する.
! 751:
! 752:
1.3 noro 753: */
754: /*&eg
1.5 noro 755: See IEEE 754 double precision floating-point (64 bit) for the details of
1.12 takayama 756: float compliant to the IEEE standard.
1.13 ! takayama 757:
! 758: The internal expression of 256.100006 in the Intel Pentium is
! 759: {\tt cd 0c 80 43 } \\
! 760: The internal expression of 256.100006 in the PowerPC (Mac) is
! 761: {\tt 43 80 0c cd }.
! 762: As you have seen in this example,
! 763: the orders of the bytes are opposite each other.
! 764: The byte order is specified by the byte order negotiation protocol
! 765: when the engine starts.
! 766:
1.3 noro 767: */
1.1 noro 768:
769: \noindent
1.4 noro 770: Group CMObject/Bigfloat requires CMObject/Primitive, CMObject/Basic.\\
1.1 noro 771: Bigfloat
772: $\in$ CMObject/Bigfloat \\
773:
774: \begin{eqnarray*}
775: \mbox{Bigfloat} &:&
776: \mbox{({\tt CMO\_BIGFLOAT}, } \\
777: & & \quad \mbox{ {\sl ZZ} a , {\sl ZZ} e})\\
1.3 noro 778: & & \mbox{ --- $a \times 2^e$. } \\
1.1 noro 779: \end{eqnarray*}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>