开发者

Calling Mathematica from OCaml program

开发者 https://www.devze.com 2023-01-14 19:27 出处:网络
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 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

精彩评论

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