Porting Mathematica to Octave

I need to transfer a large number of files from Mathematica to Octave. I found the Lisp Mathematica parser from ~ 1991 , but I'm not very familiar with Lisp, so I was wondering if anyone had any experience with porting in that direction. After researching and sending WolframAlpha's email and no real results, I would have to use Lex and Yacc to create a cross-compiler. It seems a little excessive to me.

Any hints or pointers are welcome.

Clarification:

I start with a large number of Mathematica files, and their functionality needs to be ported to Octave. I just want to achieve this goal as little time as possible, because this is the task that my boss gave me to do during the holidays. Thanks for your help, I'll take a look at FullForm and study the Mathematica file for non-portable content. If you can simply convert a certain number of files, I would have to do the rest manually, which will take some time. Thus, it is basically one time to switch from one program to another.

As mentioned in a post in Leonid, the task seems excessive, but I am an assistant for students, and this is exactly what I have to do in my department.

+5
source share
3 answers

I work both with MATLAB (the $$$$ version of Octave) and with Mathematica quite regularly, and I'm pretty sure that it is not possible to implement a parser / porter that automatically converts from Mathematica to another. First, MATLAB / Octave does not support pattern matching or rewriting of terms or functional programming, all of which are the most common and optimal coding styles in Mathematica.

For example, consider a pure function (Mathematica)

f = #^2&;

There really is no equivalent in MATLAB / Octave. Anonymous functions are pretty close, and you can write them as (MATLAB / Octave)

g=@(x)x.^2;

, Mathematica , , MATLAB //. , , , , .

, MATLAB/Octave, - / SetDelayed := . ,

f := a #^2 &;

f a f. , :

g = @(x)a*x.^2;

a , . .

, Mathematica, . Mathematica, . , , .


, Mathematica MATLAB/Octave, ToMatlab. , Mathematica MATLAB. :

expr = Sin[x + x^3] + ArcSin[y];
ToMatlab[expr]
Out[1]= sin(x + x.^3) + asin(y)
+18

Mathematica . Mathematica Mathematica. , SymbolicC. , Mathematica ( SymbolicOctave), , , say ToOctaveCodeString. SymbolicC, , C - Mathematica.

, Mathematica SymbolicOctave. , () Mathematica , , Octave. Mathematica Mathematica, . , Mathematica.

, Mathematica, . Mathematica, . Mathematica Octave , Octave, ( ). Mathematica ( , , Octave), , .

+11

The idiomatic way to generate code for a less capable system from Mathematica is not to use a third-party tool (which should be as powerful as the Mathematica kernel), but to use Mathematica itself.

Some of this type of code generator are already available out of the box (for C and Fortran), see how they are implemented, and then reconfigure them for Octave / Matlab.

+2
source

All Articles