开发者

Calling Mathematica from OCaml program

I am writing OCaml code. In part of it, I want to examine whether two arithmetic expression are equal (like x+2+y == x+2*y-y+2). Implemeting this in mathematica is straightforward, so all 开发者_JS百科I want some help on executing Mathematica and get the result back in OCaml. My OS platform is Linux.

Cheers, Z.


You may be able to use something along the lines of this:

let channel_to_mathematica, channel_from_mathematica = open_process "mathematica"
in
Printf.fprintf channel_to_mathematica "Tell me if this is equal ...\n";
let answer_from_mathematica = Scanf.fscanf channel_from_mathematica ... 
in
...

Documentation of open_process here

Documentation of module Scanf here


A very general answer is to write a command-line Mathematica script that takes 2 expressions (either on the command line or stdin) and outputs whether they are equal. Then in OCaml simply call that program with a system call.

As for writing such a command-line Mathematica script, I recommend MASH (disclosure: I made MASH): Call a Mathematica program from the command line, with command-line args, stdin, stdout, and stderr

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜