views:

62

answers:

2

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 I want some help on executing Mathematica and get the result back in OCaml. My OS platform is Linux.

Cheers, Z.

+3  A: 

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

Pascal Cuoq
+2  A: 

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): http://stackoverflow.com/questions/148057/call-a-mathematica-program-from-the-command-line

dreeves