Annotation of OpenXM/src/asir-contrib/packages/doc/m.oxweave, Revision 1.5
1.5 ! ohara 1: /* $OpenXM: OpenXM/src/asir-contrib/packages/doc/m.oxweave,v 1.4 2003/07/27 13:18:46 takayama Exp $ */
1.1 takayama 2: /* Use oxweave to generate documents on this source code
3: Use iso-2022 to write this file. No default use of GL and GR is allowed.
4: */
5:
6:
7: /*&C-texi
8: @c DO NOT EDIT THIS FILE oxmath.texi It is automatically generated
9: @c from asir-contrib/packages/doc/m.oxweave
10: @node Mathematica Functions,,, Top
1.4 takayama 11: @menu
12: * mathematica.start::
13: * mathematica.tree_to_string::
14: * mathematica.rtomstr::
15: @end menu
16:
17:
1.1 takayama 18: */
1.5 ! ohara 19: /*&ja
1.1 takayama 20: @chapter Mathematica $BH!?t(B
21:
22: $B$3$N@a$G$O(B Mathematica $B$N(B ox $B%5!<%P(B @code{ox_math}
23: $B$H$N%$%s%?%U%'!<%94X?t$r2r@b$9$k(B.
24: $B$3$l$i$N4X?t$O%U%!%$%k(B @file{m} $B$GDj5A$5$l$F$$$k$N$G$3$N%U%!%$%k$r(B
25: @code{load("m")$} $B$G$3$N%U%!%$%k$r%m!<%I$7$F$+$i;HMQ$7$J$$$H$$$1$J$$(B.
26: @file{m} $B$O(B @file{$(OpenXM_HOME)/lib/asir-contrib} $B$K$"$k(B.
27:
28: $BCm0U(B: @code{ox_reset} $B$OF0$+$J$$(B.
29: */
1.5 ! ohara 30: /*&en
1.1 takayama 31: @chapter Mathematica Functions
32:
33: This chapter describes interface functions for
34: Mathematica ox server @code{ox_math}.
35: These interface functions are defined in the file @file{m}.
36: You need to load the file before using the interface functions.
37: by the command @code{load("m")$}.
38: The file @file{m} is at @file{$(OpenXM_HOME)/lib/asir-contrib}.
39:
40: Note: @code{ox_reset} does not work.
41: */
42: /*&C-texi
43: @example
44: @include opening.texi
45: [258] load("m")$
1.2 takayama 46: m Version 19991113. mathematica.start, mathematica.tree_to_string, mathematica.n_Eigenvalues
47: [259] mathematica.start();
1.1 takayama 48: ox_math has started.
49: ox_math: Portions copyright 2000 Wolfram Research, Inc.
50: See OpenXM/Copyright/Copyright.mathlink for details.
51: 0
1.2 takayama 52: [260] mathematica.n_Eigenvalues([[1,2],[4,5]]);
1.1 takayama 53: [-0.464102,6.4641]
54: @end example
55: */
56:
57: /*&C-texi
58: @noindent
59: @code{Mathematica} is the trade mark of Wolfram Research Inc.
60: This package requires Mathmatica Version 3.0, so you need
61: Mathematica to make this package work.
62: See @code{http://www.wolfram.com}.
63: The copyright and license agreement of the mathlink is put at
64: @code{OpenXM/Copyright/Copyright.mathlink}
65: Note that the licence prohibits to connect to a mathematica
66: kernel via the internet.
67:
68: @noindent
69: Author of @code{ox_math}: Katsuyoshi Ohara,
70: @code{ohara@@air.s.kanazawa-u.ac.jp}.
71: */
72:
73:
1.5 ! ohara 74: /*&ja
1.1 takayama 75: @section $BH!?t0lMw(B
76: */
1.5 ! ohara 77: /*&en
1.1 takayama 78: @section Functions
79: */
1.5 ! ohara 80: /*&ja
1.2 takayama 81: @node mathematica.start,,, Mathematica Functions
82: @subsection @code{mathematica.start}
83: @findex mathematica.start
1.1 takayama 84: @table @t
1.2 takayama 85: @item mathematica.start()
1.1 takayama 86: :: Localhost $B$G(B @code{ox_math} $B$r5/F0$9$k(B.
87: @end table
88:
89: @table @var
90: @item return
91: $B@0?t(B
92: @end table
93:
94: @itemize @bullet
95: @item Localhost $B$G(B @code{ox_math} $B$r5/F0$9$k(B.
96: $B5/F0$5$l$?(B @code{ox_math} $B$N<1JLHV9f$rLa$9(B.
97: @item @code{Xm_noX =1} $B$H$7$F$*$/$H(B, @code{ox_math} $BMQ$N(B debug window $B$,3+$+$J$$(B.
98: @item $B<1JLHV9f$O(B @code{M_proc} $B$K3JG<$5$l$k(B.
99: @end itemize
100: */
1.5 ! ohara 101: /*&en
1.2 takayama 102: @node mathematica.start,,, Mathematica Functions
103: @subsection @code{mathematica.start}
104: @findex mathematica.start
1.1 takayama 105: @table @t
1.2 takayama 106: @item mathematica.start()
1.1 takayama 107: :: Start @code{ox_math} on the localhost.
108: @end table
109:
110: @table @var
111: @item return
112: Integer
113: @end table
114:
115: @itemize @bullet
116: @item Start @code{ox_math} on the localhost.
117: It returns the descriptor of @code{ox_math}.
118: @item Set @code{Xm_noX = 1} to start @code{ox_math} without a debug window.
119: @item The descriptor is stored in the variable @code{M_proc}.
120: @end itemize
121: */
122: /*&C-texi
123: @example
1.2 takayama 124: P = mathematica.start()
1.1 takayama 125: @end example
126: */
1.5 ! ohara 127: /*&ja
1.1 takayama 128: @table @t
129: @item $B;2>H(B
130: @code{ox_launch}
131: @end table
132: */
1.5 ! ohara 133: /*&en
1.1 takayama 134: @table @t
135: @item Reference
136: @code{ox_launch}
137: @end table
138: */
139:
140: /*&jp
141: $B0J2<$G(BMathematica $B$r8F$V$?$a$NJd=u4X?t$rDj5A$9$k(B.
142: */
143:
1.5 ! ohara 144: /*&ja
1.2 takayama 145: @node mathematica.tree_to_string,,, Mathematica Functions
146: @subsection @code{mathematica.tree_to_string}
147: @findex mathematica.tree_to_string
1.1 takayama 148: @table @t
1.2 takayama 149: @item mathematica.tree_to_string(@var{t})
1.1 takayama 150: :: ox_math $B$NLa$9(B Mathematica $B$NLZ9=B$%G!<%?(B @var{t} $B$r(B @code{asir} $B7A<0$K(B
151: $B$J$*$9(B.
152: @end table
153:
154: @table @var
155: @item return
156: $BJ8;zNs(B
157: @item t
158: $B%j%9%H(B
159: @end table
160: @itemize @bullet
161: @item
162: t $B$O(B @code{ox_math} $B$NLa$9(B Mathematica $B$NLZ9=B$%G!<%?(B.
163: @item
164: ox_math $B$NLa$9(B Mathematica $B$NLZ9=B$%G!<%?(B @var{t} $B$r(B @code{asir} $B7A<0$K(B
165: $B$J$*$9(B.
166: @item
167: @var{t} $B$r$J$k$Y$/(B asir $B$,M}2r$G$-$k7A$G$N(B, $BA0CV$^$?$OCfCV5-K!(B
168: $B$NJ8;zNs$KJQ49$9$k(B.
169: @var{t}$B$N@hF,MWAG$NJ8;zNs$,%-!<%o!<%I$G$"$k$,(B, $B$=$NJ8;z$,JQ49%F!<%V%k$K$J$$(B
170: $B$H$-$O(B, @code{m_} $B$r%-!<%o!<%I$N@hF,$K$D$1$F(B, $B4X?t8F=P7A<0$NJ8;zNs$X(B
171: $B$+$($k(B.
172: @end itemize
173: */
1.5 ! ohara 174: /*&en
1.2 takayama 175: @node mathematica.tree_to_string,,, Mathematica Functions
176: @subsection @code{mathematica.tree_to_string}
177: @findex mathematica.tree_to_string
1.1 takayama 178: @table @t
1.2 takayama 179: @item mathematica.tree_to_string(@var{t})
1.1 takayama 180: :: translates Mathematica tree data @var{t} into a string that can
181: be understandable by @code{asir} as far as possible.
182: @end table
183:
184: @table @var
185: @item return
186: String
187: @item t
188: List
189: @end table
190: @itemize @bullet
191: @item
192: t is a Mathematica tree data which is generated by @code{ox_math}.
193: @item
194: This function
195: translates Mathematica tree data @var{t} into a string that may
196: be understandable by @code{asir}.
197: @item
198: This function translates @var{t} into a prefix or infix expression that may be understantable by @code{asir}.
199: The first element of the list @var{t}
200: is a key word string of the Mathematica object.
201: If this function recognizes the key word, it translates @code{t} into
202: the form that can be understandable by @code{asir}.
203: If it cannot recognizes the key word, it translates @code{t} into
204: a function call with the function name
205: @code{m_(the key word)}.
206: @end itemize
207: */
208: /*&C-texi
209: @example
1.2 takayama 210: [267] mathematica.start();
1.1 takayama 211: 0
212: [268] ox_execute_string(0,"Expand[(x-1)^2]");
213: 0
214: [269] A=ox_pop_cmo(0);
215: [Plus,1,[Times,-2,x],[Power,x,2]]
1.2 takayama 216: [270] mathematica.tree_to_string(A);
1.1 takayama 217: (1)+((-2)*(x))+((x)^(2))
218: [271] eval_str(@@);
219: x^2-2*x+1
220: @end example
221: */
222: /*&C-texi
223: @example
1.2 takayama 224: [259] mathematica.tree_to_string(["List",1,2]);
1.1 takayama 225: [1 , 2]
1.2 takayama 226: [260] mathematica.tree_to_string(["Plus",2,3]);
1.1 takayama 227: (2)+(3)
1.2 takayama 228: [261] mathematica.tree_to_string(["Complex",2.3,4.55]);
229: mathematica.complex(2.3 , 4.55)
230: [362] mathematica.tree_to_string(["Plus",["Complex",1.2,3.5],1/2]);
231: (mathematica.complex(1.2 , 3.5))+(1/2)
1.1 takayama 232: [380] eval_str(@@);
1.3 takayama 233: (1.7+3.5*@@i)
1.1 takayama 234: @end example
235: */
1.5 ! ohara 236: /*&ja
1.1 takayama 237: @table @t
238: @item $B;2>H(B
1.2 takayama 239: @code{ox_pop_cmo}, @code{eval_str}, @code{mathematica.rtomstr}
1.1 takayama 240: @end table
241: */
1.5 ! ohara 242: /*&en
1.1 takayama 243: @table @t
244: @item Reference
1.2 takayama 245: @code{ox_pop_cmo}, @code{eval_str}, @code{mathematica.rtomstr}
1.1 takayama 246: @end table
247: */
248: /*&jp
249: {\tt m\_tree\_to\_string(L)} $B$O(B, {\tt MathLink} $B$N(B $BLZ7A<0$GM?$($l$?(B
250: $B%*%V%8%(%'%/%H$r$J$k$Y$/(B asir $B$,M}2r$G$-$k7A$G$N(B, $BA0CV$^$?$OCfCV5-K!(B
251: $B$NJ8;zNs$KJQ49$9$k(B. \\
252: $BNc(B: {\tt m\_tree\_to\_string(["Plus",1,2])} $B$OJ8;zNs(B
253: {\tt 1+2} $B$rLa$9(B. \\
254: $B%j%9%H$N@hF,$NJ8;zNs$,%-!<%o!<%I$G$"$k$,(B, $B$=$NJ8;z$,JQ49%F!<%V%k$K$J$$(B
255: $B$H$-$O(B, {\tt m\_} $B$r%-!<%o!<%I$N@hF,$K$D$1$F(B, $B4X?t8F=P7A<0$NJ8;zNs$X(B
256: $BJQ$($k(B.
257: */
258:
1.5 ! ohara 259: /*&ja
1.2 takayama 260: @node mathematica.rtomstr,,, Mathematica Functions
261: @subsection @code{mathematica.rtomstr}
262: @findex mathematica.rtomstr
1.1 takayama 263: @table @t
1.2 takayama 264: @item mathematica.rtomstr(@var{t})
1.1 takayama 265: :: @var{t} $B$r$J$k$Y$/(B Mathematica $B$NM}2r2DG=$JJ8;zNs$KJQ$($k(B.
266: @end table
267:
268: @table @var
269: @item return
270: $BJ8;zNs(B
271: @item t
272: $B%*%V%8%'%/%H(B
273: @end table
274: @itemize @bullet
275: @item
276: @var{t} $B$r$J$k$Y$/(B Mathematica $B$,M}2r$G$-$k7A$NJ8;zNs$KJQ49$9$k(B.
277: $B$?$H$($P(B, @code{asir} $B$G$O%j%9%H$r(B @code{[}, @code{]} $B$G0O$`$,(B,
278: Mathematica $B$G$O(B @code{@{}, @code{@}} $B$G0O$`(B.
279: $B$3$N4X?t$O$3$NJQ49$r$*$3$J$&(B.
280: @end itemize
281: */
1.5 ! ohara 282: /*&en
1.2 takayama 283: @node mathematica.rtomstr,,, Mathematica Functions
284: @subsection @code{mathematica.rtomstr}
285: @findex mathematica.rtomstr
1.1 takayama 286: @table @t
1.2 takayama 287: @item mathematica.rtomstr(@var{t})
1.1 takayama 288: :: translate the object @var{t} into a string that can be understandable
289: by Mathematica as far as possible.
290: @end table
291:
292: @table @var
293: @item return
294: String
295: @item t
296: Object
297: @end table
298: @itemize @bullet
299: @item
300: It translates the object @var{t} into a string that can be understandable
301: by Mathematica as far as possible.
302: For example, @code{asir} uses @code{[}, @code{]} to express a list,
303: but @code{Mathematica} uses @code{@{}, @code{@}}.
304: This function makes this sort of translations.
305: @end itemize
306: */
307: /*&C-texi
308: @example
1.2 takayama 309: [259] mathematica.rtomstr([1,2,3]);
1.3 takayama 310: @{1,2,3@}
1.2 takayama 311: [260] mathematica.rtomstr([[1,x,x^2],[1,y,y^2]]);
1.1 takayama 312: @{@{1,x,x^2@},@{1,y,y^2@}@}
313: @end example
314: */
1.5 ! ohara 315: /*&ja
1.1 takayama 316: $B$b$&0l$DNc$r$"$2$h$&(B.
1.2 takayama 317: $B<!$N4X?t(B @code{mathematica.inverse(M)} $B$O(B @code{ox_math}
1.1 takayama 318: $B$r$h$s$G9TNs(B @code{M} $B$N5U9TNs$r7W;;$9$k4X?t$G$"$k(B.
1.2 takayama 319: @code{mathematica.inverse(M)} $B$O<!$N$h$&$K(B @code{r_tostr(M)} $B$rMQ$$$F(B
1.1 takayama 320: asir $B$N9TNs$r(B Mathematica $B7A<0$KJQ49$7$F$+$i(B
321: @code{ox_execute_string} $B$G(B Mathematica $B$K5U9TNs$r7W;;(B
322: $B$5$;$F$$$k(B.
323: */
1.5 ! ohara 324: /*&en
1.1 takayama 325: Let us see one more example.
1.2 takayama 326: The following function @code{mathematica.inverse(M)} outputs
1.1 takayama 327: the inverse matrix of the matrix @code{M} by calling @code{ox_math}.
328: It translates @code{asir} matrix @code{M} into a Mathematica expression
329: by @code{r_tostr(M)}
330: and makes Mathematica compute the inverse matrix of @code{M} by
331: @code{ox_execute_string}.
332: */
333: /*&C-texi
334: @example
335: def inverse(M) @{
336: P = 0;
1.2 takayama 337: A = mathematica.rtomstr(M);
1.1 takayama 338: ox_execute_string(P,"Inverse["+A+"]");
339: B = ox_pop_cmo(B);
1.2 takayama 340: C = mathematica.tree_to_string(B);
1.1 takayama 341: return(eval_str(C));
342: @}
343:
344: [269] M=[[1,x,x^2],[1,y,y^2],[1,z,z^2]];
345: [[1,x,x^2],[1,y,y^2],[1,z,z^2]]
1.2 takayama 346: [270] A=mathematica.inverse(M)$
1.1 takayama 347: [271] red(A[0][0]);
348: (z*y)/(x^2+(-y-z)*x+z*y)
349: @end example
350: */
1.5 ! ohara 351: /*&ja
1.1 takayama 352: @table @t
353: @item $B;2>H(B
354: @code{ox_execute_string}, @code{ToExpression}(Mathematica),
1.2 takayama 355: @code{mathematica.tree_to_string}
1.1 takayama 356: @end table
357: */
1.5 ! ohara 358: /*&en
1.1 takayama 359: @table @t
360: @item Reference
361: @code{ox_execute_string}, @code{ToExpression}(Mathematica),
1.2 takayama 362: @code{mathematica.tree_to_string}
1.1 takayama 363: @end table
364: */
365: /*&jp
1.2 takayama 366: $B4X?t(B \verb+ mathematica.rtomstr(L) + $B$O(B asir $B7A<0$N%*%V%8%'%/%H(B L $B$r$J$k$Y$/(B
1.1 takayama 367: Mathematica $B$,M}2r$G$-$k7A$NJ8;zNs$KJQ49$9$k(B.
368: $B$?$H$($P(B, $B%j%9%H(B, $B%Y%/%H%k(B, $B9TNs(B $B$O(B asir $B$G$O(B {\tt [}, {\tt ]}
369: $B$G0O$`$,(B, Mathematica $B$G$O(B, {\tt \{ }, {\tt \}} $B$G0O$`(B.
370: $B8=:_$N$H$3$m$3$N4X?t$O$3$NJQ49$N$_9T$J$C$F$$$k(B. \\
371: $BNc(B:
372: {\footnotesize
373: \begin{verbatim}
1.2 takayama 374: [262] mathematica.rtomstr([1,2,3]);
1.1 takayama 375: {1,2,3}
376: [375] A = newvect(3,[x+2,"Hello",[1/2,3]]);
377: [ x+2 Hello [1/2,3] ]
1.2 takayama 378: [376] mathematica.rtomstr(A);
1.1 takayama 379: {x+2,Hello,{1/2,3}}
380: \end{verbatim}
381: }
382: */
383:
384: end$
385:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>