我在寫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