Mathematica OX server Manual

Edition : auto generated by oxgentexi on 23 February 2009

OpenXM.org

1 Mathematica Functions

This chapter describes interface functions for Mathematica ox server ox_math. These interface functions are defined in the file ‘mathematica.rr’. You need to load the file before using the interface functions. by the command load("m")$. The file ‘mathematica.rr’ is

at ‘$(OpenXM_HOME)/lib/asir-contrib’.

Note: ox_reset does not work.

     [258] load("mathematica.rr")$
     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]

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 http://www.wolfram.com. The copyright and license agreement of the mathlink is put at OpenXM/Copyright/Copyright.mathlink Note that the licence prohibits to connect to a mathematica kernel via the internet. Author of ox_math: Katsuyoshi Ohara.

1.1 Functions

1.1.1 mathematica.start
mathematica.start()

:: Start ox_math on the localhost.

return Integer • Start ox_math on the localhost. It returns the descriptor of ox_math.

• Set Xm_noX = 1 to start ox_math without a debug window.

• The descriptor is stored in the variable M_proc.

     P = mathematica.start()
Reference
          ox_launch
1.1.2 mathematica.tree_to_string
mathematica.tree_to_string(t)

:: translates Mathematica tree data t into a string that can be understandable by asir as far as possible. return String

t List • t is a Mathematica tree data which is generated by ox_math.

• This function translates Mathematica tree data t into a string that may be understandable by asir.

• This function translates t into a prefix or infix expression that may be understantable by asir. The first element of the list t is a key word string of the Mathematica object. If this function recognizes the key word, it translates t into the form that can be understandable by asir. If it cannot recognizes the key word, it translates t into a function call with the function name m_(the key word).

[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
[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)
Reference
     ox_pop_cmo, eval_str, mathematica.rtomstr
1.1.3 mathematica.rtomstr
mathematica.rtomstr(t)

:: translate the object t into a string that can be understandable by Mathematica as far as possible.

return String

t Object

• It translates the object t into a string that can be understandable by Mathematica as far as possible. For example, asir uses [, ] to express a list, but Mathematica uses {, }. This function makes this sort of translations.

[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}}

Let us see one more example. The following function mathematica.inverse(M) outputs the inverse matrix of the matrix M by calling ox_math. It translates asir matrix M into a Mathematica expression by r_tostr(M) and makes Mathematica compute the inverse

matrix of M by ox_execute_string.
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)
Reference
     ox_execute_string, ToExpression(Mathematica), mathematica.tree_to_
     string

Index 4

Index

(Index is nonexistent) (Index is nonexistent)

Short Contents

1 Mathematica Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Table of Contents

1 Mathematica Functions . . . . . . . . . . . . . . . . . . . . 1

1.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 mathematica.start . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.2 mathematica.tree_to_string . . . . . . . . . . . . . . . . . . 1

1.1.3 mathematica.rtomstr . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4