/* $OpenXM: OpenXM/src/asir-contrib/packages/doc/m.oxweave,v 1.4 2003/07/27 13:18:46 takayama Exp $ */ /* Use oxweave to generate documents on this source code Use iso-2022 to write this file. No default use of GL and GR is allowed. */ /*&C-texi @c DO NOT EDIT THIS FILE oxmath.texi It is automatically generated @c from asir-contrib/packages/doc/m.oxweave @node Mathematica Functions,,, Top @menu * mathematica.start:: * mathematica.tree_to_string:: * mathematica.rtomstr:: @end menu */ /*&jp-texi @chapter Mathematica 函数 この節では Mathematica の ox サーバ @code{ox_math} とのインタフェース関数を解説する. これらの関数はファイル @file{m} で定義されているのでこのファイルを @code{load("m")$} でこのファイルをロードしてから使用しないといけない. @file{m} は @file{$(OpenXM_HOME)/lib/asir-contrib} にある. 注意: @code{ox_reset} は動かない. */ /*&eg-texi @chapter Mathematica Functions This chapter describes interface functions for Mathematica ox server @code{ox_math}. These interface functions are defined in the file @file{m}. You need to load the file before using the interface functions. by the command @code{load("m")$}. The file @file{m} is at @file{$(OpenXM_HOME)/lib/asir-contrib}. Note: @code{ox_reset} does not work. */ /*&C-texi @example @include opening.texi [258] load("m")$ m Version 19991113. mathematica.start, mathematica.tree_to_string, mathematica.n_Eigenvalues [259] mathematica.start(); ox_math has started. ox_math: Portions copyright 2000 Wolfram Research, Inc. See OpenXM/Copyright/Copyright.mathlink for details. 0 [260] mathematica.n_Eigenvalues([[1,2],[4,5]]); [-0.464102,6.4641] @end example */ /*&C-texi @noindent @code{Mathematica} is the trade mark of Wolfram Research Inc. This package requires Mathmatica Version 3.0, so you need Mathematica to make this package work. See @code{http://www.wolfram.com}. The copyright and license agreement of the mathlink is put at @code{OpenXM/Copyright/Copyright.mathlink} Note that the licence prohibits to connect to a mathematica kernel via the internet. @noindent Author of @code{ox_math}: Katsuyoshi Ohara, @code{ohara@@air.s.kanazawa-u.ac.jp}. */ /*&jp-texi @section 函数一覧 */ /*&eg-texi @section Functions */ /*&jp-texi @node mathematica.start,,, Mathematica Functions @subsection @code{mathematica.start} @findex mathematica.start @table @t @item mathematica.start() :: Localhost で @code{ox_math} を起動する. @end table @table @var @item return 整数 @end table @itemize @bullet @item Localhost で @code{ox_math} を起動する. 起動された @code{ox_math} の識別番号を戻す. @item @code{Xm_noX =1} としておくと, @code{ox_math} 用の debug window が開かない. @item 識別番号は @code{M_proc} に格納される. @end itemize */ /*&eg-texi @node mathematica.start,,, Mathematica Functions @subsection @code{mathematica.start} @findex mathematica.start @table @t @item mathematica.start() :: Start @code{ox_math} on the localhost. @end table @table @var @item return Integer @end table @itemize @bullet @item Start @code{ox_math} on the localhost. It returns the descriptor of @code{ox_math}. @item Set @code{Xm_noX = 1} to start @code{ox_math} without a debug window. @item The descriptor is stored in the variable @code{M_proc}. @end itemize */ /*&C-texi @example P = mathematica.start() @end example */ /*&jp-texi @table @t @item 参照 @code{ox_launch} @end table */ /*&eg-texi @table @t @item Reference @code{ox_launch} @end table */ /*&jp 以下でMathematica を呼ぶための補助関数を定義する. */ /*&jp-texi @node mathematica.tree_to_string,,, Mathematica Functions @subsection @code{mathematica.tree_to_string} @findex mathematica.tree_to_string @table @t @item mathematica.tree_to_string(@var{t}) :: ox_math の戻す Mathematica の木構造データ @var{t} を @code{asir} 形式に なおす. @end table @table @var @item return 文字列 @item t リスト @end table @itemize @bullet @item t は @code{ox_math} の戻す Mathematica の木構造データ. @item ox_math の戻す Mathematica の木構造データ @var{t} を @code{asir} 形式に なおす. @item @var{t} をなるべく asir が理解できる形での, 前置または中置記法 の文字列に変換する. @var{t}の先頭要素の文字列がキーワードであるが, その文字が変換テーブルにない ときは, @code{m_} をキーワードの先頭につけて, 関数呼出形式の文字列へ かえる. @end itemize */ /*&eg-texi @node mathematica.tree_to_string,,, Mathematica Functions @subsection @code{mathematica.tree_to_string} @findex mathematica.tree_to_string @table @t @item mathematica.tree_to_string(@var{t}) :: translates Mathematica tree data @var{t} into a string that can be understandable by @code{asir} as far as possible. @end table @table @var @item return String @item t List @end table @itemize @bullet @item t is a Mathematica tree data which is generated by @code{ox_math}. @item This function translates Mathematica tree data @var{t} into a string that may be understandable by @code{asir}. @item This function translates @var{t} into a prefix or infix expression that may be understantable by @code{asir}. The first element of the list @var{t} is a key word string of the Mathematica object. If this function recognizes the key word, it translates @code{t} into the form that can be understandable by @code{asir}. If it cannot recognizes the key word, it translates @code{t} into a function call with the function name @code{m_(the key word)}. @end itemize */ /*&C-texi @example [267] mathematica.start(); 0 [268] ox_execute_string(0,"Expand[(x-1)^2]"); 0 [269] A=ox_pop_cmo(0); [Plus,1,[Times,-2,x],[Power,x,2]] [270] mathematica.tree_to_string(A); (1)+((-2)*(x))+((x)^(2)) [271] eval_str(@@); x^2-2*x+1 @end example */ /*&C-texi @example [259] mathematica.tree_to_string(["List",1,2]); [1 , 2] [260] mathematica.tree_to_string(["Plus",2,3]); (2)+(3) [261] mathematica.tree_to_string(["Complex",2.3,4.55]); mathematica.complex(2.3 , 4.55) [362] mathematica.tree_to_string(["Plus",["Complex",1.2,3.5],1/2]); (mathematica.complex(1.2 , 3.5))+(1/2) [380] eval_str(@@); (1.7+3.5*@@i) @end example */ /*&jp-texi @table @t @item 参照 @code{ox_pop_cmo}, @code{eval_str}, @code{mathematica.rtomstr} @end table */ /*&eg-texi @table @t @item Reference @code{ox_pop_cmo}, @code{eval_str}, @code{mathematica.rtomstr} @end table */ /*&jp {\tt m\_tree\_to\_string(L)} は, {\tt MathLink} の 木形式で与えれた オブジエェクトをなるべく asir が理解できる形での, 前置または中置記法 の文字列に変換する. \\ 例: {\tt m\_tree\_to\_string(["Plus",1,2])} は文字列 {\tt 1+2} を戻す. \\ リストの先頭の文字列がキーワードであるが, その文字が変換テーブルにない ときは, {\tt m\_} をキーワードの先頭につけて, 関数呼出形式の文字列へ 変える. */ /*&jp-texi @node mathematica.rtomstr,,, Mathematica Functions @subsection @code{mathematica.rtomstr} @findex mathematica.rtomstr @table @t @item mathematica.rtomstr(@var{t}) :: @var{t} をなるべく Mathematica の理解可能な文字列に変える. @end table @table @var @item return 文字列 @item t オブジェクト @end table @itemize @bullet @item @var{t} をなるべく Mathematica が理解できる形の文字列に変換する. たとえば, @code{asir} ではリストを @code{[}, @code{]} で囲むが, Mathematica では @code{@{}, @code{@}} で囲む. この関数はこの変換をおこなう. @end itemize */ /*&eg-texi @node mathematica.rtomstr,,, Mathematica Functions @subsection @code{mathematica.rtomstr} @findex mathematica.rtomstr @table @t @item mathematica.rtomstr(@var{t}) :: translate the object @var{t} into a string that can be understandable by Mathematica as far as possible. @end table @table @var @item return String @item t Object @end table @itemize @bullet @item It translates the object @var{t} into a string that can be understandable by Mathematica as far as possible. For example, @code{asir} uses @code{[}, @code{]} to express a list, but @code{Mathematica} uses @code{@{}, @code{@}}. This function makes this sort of translations. @end itemize */ /*&C-texi @example [259] mathematica.rtomstr([1,2,3]); @{1,2,3@} [260] mathematica.rtomstr([[1,x,x^2],[1,y,y^2]]); @{@{1,x,x^2@},@{1,y,y^2@}@} @end example */ /*&jp-texi もう一つ例をあげよう. 次の関数 @code{mathematica.inverse(M)} は @code{ox_math} をよんで行列 @code{M} の逆行列を計算する関数である. @code{mathematica.inverse(M)} は次のように @code{r_tostr(M)} を用いて asir の行列を Mathematica 形式に変換してから @code{ox_execute_string} で Mathematica に逆行列を計算 させている. */ /*&eg-texi Let us see one more example. The following function @code{mathematica.inverse(M)} outputs the inverse matrix of the matrix @code{M} by calling @code{ox_math}. It translates @code{asir} matrix @code{M} into a Mathematica expression by @code{r_tostr(M)} and makes Mathematica compute the inverse matrix of @code{M} by @code{ox_execute_string}. */ /*&C-texi @example def inverse(M) @{ P = 0; A = mathematica.rtomstr(M); ox_execute_string(P,"Inverse["+A+"]"); B = ox_pop_cmo(B); C = mathematica.tree_to_string(B); return(eval_str(C)); @} [269] M=[[1,x,x^2],[1,y,y^2],[1,z,z^2]]; [[1,x,x^2],[1,y,y^2],[1,z,z^2]] [270] A=mathematica.inverse(M)$ [271] red(A[0][0]); (z*y)/(x^2+(-y-z)*x+z*y) @end example */ /*&jp-texi @table @t @item 参照 @code{ox_execute_string}, @code{ToExpression}(Mathematica), @code{mathematica.tree_to_string} @end table */ /*&eg-texi @table @t @item Reference @code{ox_execute_string}, @code{ToExpression}(Mathematica), @code{mathematica.tree_to_string} @end table */ /*&jp 関数 \verb+ mathematica.rtomstr(L) + は asir 形式のオブジェクト L をなるべく Mathematica が理解できる形の文字列に変換する. たとえば, リスト, ベクトル, 行列 は asir では {\tt [}, {\tt ]} で囲むが, Mathematica では, {\tt \{ }, {\tt \}} で囲む. 現在のところこの関数はこの変換のみ行なっている. \\ 例: {\footnotesize \begin{verbatim} [262] mathematica.rtomstr([1,2,3]); {1,2,3} [375] A = newvect(3,[x+2,"Hello",[1/2,3]]); [ x+2 Hello [1/2,3] ] [376] mathematica.rtomstr(A); {x+2,Hello,{1/2,3}} \end{verbatim} } */ end$