我在写OCaml代码。在其中的一部分,我想检查两个算术表达式是否相等(如x + 2 + y == x + 2 * y-y + 2)。在mathematica中实现这一点很简单,所以我希望在执行Mathematica时获得一些帮助,并在OCaml中获得结果。我的操作系统平台是Linux。从OCaml程序调用Mathematica
干杯, Z.
我在写OCaml代码。在其中的一部分,我想检查两个算术表达式是否相等(如x + 2 + y == x + 2 * y-y + 2)。在mathematica中实现这一点很简单,所以我希望在执行Mathematica时获得一些帮助,并在OCaml中获得结果。我的操作系统平台是Linux。从OCaml程序调用Mathematica
干杯, Z.
您可以沿着这个线路使用的东西:
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
...
一个非常一般的回答是写一个命令行Mathematica脚本,可以使用2个表达式(在命令行或stdin中)和outpu他们是否平等。 然后在OCaml中简单地使用系统调用调用该程序。
作为用于编写这样的命令行脚本的Mathematica,我建议MASH(披露:我制成MASH): Call a Mathematica program from the command line, with command-line args, stdin, stdout, and stderr